[Tutor] Error in programming

Lea Parker lea-parker at bigpond.com
Fri Mar 25 06:27:41 CET 2011


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110325/2a3d1c33/attachment-0001.html>


More information about the Tutor mailing list