[Tutor] I don't know why this program doesn't run

Mark Lawrence breamoreboy at yahoo.co.uk
Sat Sep 22 01:53:08 CEST 2012


On 22/09/2012 00:34, Gina wrote:
> I don't know why this program doesn't run, but if you know, please tell me.
> -thanks
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

It helps us to help you if you give your OS, the complete error message 
that you get and your version of Python as well as the code.  "This 
program doesn't run" isn't much to go on.  Also putting a small piece of 
code inline rather than as an attachment is perfectly acceptable which 
I'll do now.

#adds extra fees to the base price of a car.

print(
"""
                   Car Salesman

Totals the base price of a car with all other fees.
Please enter the requested information, and don't include
change.

"""
)

name = input("What kind of car is it?")
base_price = input("What is the base price?")

tax = base_price / 25
print("Tax: $", tax)

license_fee = base_price // 50
print("The license fee: $", license_fee)

maintenance = 45
print("The maintenance fee: $", maintenance)

insurance = 100
print("The insurance: $", insurance)

total = base_price + tax + license_fee + maintenance + insurance
print("After tax, the license fee, the maintenance fee, and the "
       "insurance fee, the ", name, "costs $", total, ".")


input("\n\nPress enter to exit.")


I'll hazard a guess that you're running Python 2.x and you get

What kind of car is it?Royce
Traceback (most recent call last):
   File "C:\Users\Mark\Car Salesperson.py", line 14, in <module>
     name = input("What kind of car is it?")
   File "<string>", line 1, in <module>
NameError: name 'Royce' is not defined

In which case change the input to raw_input and carry on to the next 
error :)

-- 
Cheers.

Mark Lawrence.



More information about the Tutor mailing list