# Python Help

3 replies to this topic

### #1 Daniel D

Daniel D

Young Padawan

• Members
• 115 posts

Posted 19 January 2007 - 05:34 PM

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!

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:
```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:

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!

Edited by Daniel D, 19 January 2007 - 05:35 PM.

### #2 EclipsE

EclipsE

Young Padawan

• Members
• 22 posts
• Gender:Male
• Location:Belgrade, Serbia
• Interests:Programming, skating, rapping...

Posted 19 January 2007 - 06:47 PM

Why don't you try changing the lines:

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

in

```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...

### #3 Daniel D

Daniel D

Young Padawan

• Members
• 115 posts

Posted 19 January 2007 - 07:24 PM

Worked perfectly, now one more thing, would you mind explaining real quick what exactly changing it to raw_input rather than input does? Thanks

Another question, how could I convert a .py to .exe with a GUI and such?

Edited by Daniel D, 19 January 2007 - 07:55 PM.

### #4 EclipsE

EclipsE

Young Padawan

• Members
• 22 posts
• Gender:Male
• Location:Belgrade, Serbia
• Interests:Programming, skating, rapping...

Posted 20 January 2007 - 07:16 AM

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...

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users