[Tutor] Error in programming
Donald Bedsole
drbedsole at gmail.com
Fri Mar 25 06:37:44 CET 2011
Hi Lea,
On Fri, Mar 25, 2011 at 1:27 AM, Lea Parker <lea-parker at bigpond.com> wrote:
> Hello
>
>
>
> Just wondering if you have some time to cast your eyes over another basic
> program.
>
>
>
> # 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
>
Don't know if it's the only problem, but :
> NameError: global name 'sale_a' is not defined
I think this comes from the fact that you spelled one variable name
"sale_a" in one place, and up where you originally assigned it you
spelled it, "sales_a."
Don
More information about the Tutor
mailing list