Help - Search - Members - Calendar
Full Version: Python Help
Pixel2Life Forum > Help Section > Desktop Programming
Daniel D
Ok well I'm 2 days into this whole programming thing, and I decided to have an attempt at my first non-reference program so that's just what I did!

My program is basically a talking calculator that calculates how many miles you get per tank of gas, and what not, it's a simple thing that popped into my head today! only problem is I got it all working, then when I decided to add a new little feature (something that calculates how many full tanks you need to go a certain amount of miles), but I keep getting the following error!

QUOTE
Traceback (most recent call last):
File "C:\Program Files\Python\gastanks.py", line 23, in <module>
c = input("Would you like to know how many full tanks you would need to get somewhere? ")
File "<string>", line 1, in <module>
NameError: name 'Yes' is not defined


Here is my syntax:
CODE
a = input("How many gallons of gas does your car hold? ")
if a > 49:
    print "We're talking about cars here not space ships!"
    print ""
else:
    print "Thank You!"
    print ""
b = input("How many miles do you get per gallon? ")
if b > 49:
    print "Ok you can stop lying now!"
    print ""
else:
    print "Thank You!"
    print ""
print "Now calculating how many miles per full tank.."

from time import sleep
sleep(4)

print "You get", a*b,"miles per full tank!"
print ""

c = input("Would you like to know how many full tanks you would need to get somewhere? ")
if c == Yes:
    print "Ok, here we go."

else:
    print "Ok, goodbye now!"


Here is how everything works up until I get the error:
QUOTE
How many gallons of gas does your car hold? 26
Thank You!

How many miles do you get per gallon? 22
Thank You!

Now calculating how many miles per full tank..
You get 572 miles per full tank!

Would you like to know how many full tanks you would need to get somewhere? Yes

Traceback (most recent call last):
File "C:\Program Files\Python\firstprog.py", line 23, in <module>
c = input("Would you like to know how many full tanks you would need to get somewhere? ")
File "<string>", line 1, in <module>
NameError: name 'Yes' is not defined


Thanks in advance!
EclipsE
Why don't you try changing the lines:

CODE
c = input("Would you like to know how many full tanks you would need to get somewhere? ")
if c == Yes:


in

CODE
c = raw_input("Would you like to know how many full tanks you would need to get somewhere? ")
if c == "Yes":


and see what happens...
Daniel D
Worked perfectly, now one more thing, would you mind explaining real quick what exactly changing it to raw_input rather than input does? Thanks smile.gif

Another question, how could I convert a .py to .exe with a GUI and such?
EclipsE
Man, i don't know anything.... I saw it quickly from a tutorial. Just go to p2l site, desktop programming, python and you have some tutorials for n00bs... I saw in one tutorial raw_input and just changed it... tongue.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.