On 3/25/2011 12:27 AM, Lea Parker wrote:
*Hello*
**
*Just wondering if you have some time to cast your eyes over another
basic program.*
Donald pointed out the first error. (actually there are 3 such spelling
errors).
When you get "name xxx is not defined" use your editor's find feature to
find where the name is defined. In this case you would not find it which
should lead you to the problem.
When you fix that you will then get
TypeError: 'str' object is not callable
on the same line of code.
Do you see why?
When you fix that you will then get either
ValueError: invalid literal for int() or
ValueError: int() base must be >= 2 and <= 36
Before returning with "why" attempt to apply the error message to the
code to see what the problems are.
Look up int() in the Python documentation
**
# Prompt user for data
def main():
print 'This program is to calculate your ticket sales to the
softball game'
print #blank line
# Value of each level of seat
a_seat = 15.00
b_seat = 12.00
c_seat = 9.00
# Obtain data
sales_a = int (raw_input('Enter the number of class A tickets sold '))
sales_b = int (raw_input('Enter the number of class B tickets sold '))
sales_c = int (raw_input('Enter the number of class C tickets sold
'))
income_generated(a_seat, b_seat, c_seat, sales_a, sales_b, sales_c)
# Obtain data to determine income generated from sales
def income_generated(a_seat, b_seat, c_seat, sales_a, sales_b, sales_c):
total_sales = """times the seat value by the number of seats sold
for each seat
and add totals togeter"""(sale_a * a_seat) + (sale_b * b_seat) +
(sale_c * c_seat)
#Display result to user
print int ('Your total sales for the softball game are: $ ',
total_sales)
# Call the main function
main()
*I get the following errors:*
>>> ================================ RESTART
================================
>>>
This program is to calculate your ticket sales to the softball game
Enter the number of class A tickets sold 5
Enter the number of class B tickets sold 5
Enter the number of class C tickets sold 10
Traceback (most recent call last):
File "F:/Backups/MY Documents26.2.11/Documents/Lea
University/CSU/ITC10 - Programming Principles/2011/Assessment
Tasks/Assessment 1b and 1c/Stadium_Seating.py", line 29, in <module>
main()
File "F:/Backups/MY Documents26.2.11/Documents/Lea
University/CSU/ITC10 - Programming Principles/2011/Assessment
Tasks/Assessment 1b and 1c/Stadium_Seating.py", line 18, in main
income_generated(a_seat, b_seat, c_seat, sales_a, sales_b, sales_c)
File "F:/Backups/MY Documents26.2.11/Documents/Lea
University/CSU/ITC10 - Programming Principles/2011/Assessment
Tasks/Assessment 1b and 1c/Stadium_Seating.py", line 23, in
income_generated
and add totals togeter"""(sale_a * a_seat) + (sale_b * b_seat) +
(sale_c * c_seat)
NameError: global name 'sale_a' is not defined
>>>
*My way of thinking is firstly I need to fix line 29 which is main(),
I tried to do this by adding the brackets around text output in line
26. This seemed to allow me to type main against margin rather than it
wanting to indent but didn't fix the problem. Your suggestions would
be appreciated.*
**
*Thank*
*Lea*
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
--
Bob Gailer
919-636-4239
Chapel Hill NC
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor