Skip to main content
GameDev.net gamedev.net
🔒 Locked

Python Help

Started by Sx2Kirby Oct 14, 2011 at 8:06 PM 2 replies 2.3k views
Original Post
Sx2Kirby
Sx2Kirby
Hello, I've been getting into python and reading a book to get used to it, but I'm having some trouble understanding a part about while loops.


done = False

while not(done):

quit = input("Do you want to quit? ")

if quit == "y":

done = True;



attack = input("Does your elf attach the dragon?")

if attack == "y" :

print ( " Bad choice , you died . " )

done = True ;

Whenever I input anything into quit it just says that it wasn't defined, and when I try defining y like : y = "y" or something it doesn't actually quit. And this is straight from the book I am learning from.

And also, what books or tutorials would you recommend?
ldmn
ldmn
free ebook
diz is a pretty kewl ebook!
That was the time, the Golden Age, when C-64 and Amiga ruled!
DaveMS
DaveMS

Hello, I've been getting into python and reading a book to get used to it, but I'm having some trouble understanding a part about while loops.


done = False

while not(done):

quit = input("Do you want to quit? ")

if quit == "y":

done = True;



attack = input("Does your elf attach the dragon?")

if attack == "y" :

print ( " Bad choice , you died . " )

done = True ;

Whenever I input anything into quit it just says that it wasn't defined, and when I try defining y like : y = "y" or something it doesn't actually quit. And this is straight from the book I am learning from.

And also, what books or tutorials would you recommend?




I'm not a python man, but I done a bit of reading around your problem. Look like Input() expects a python expression to be entered as input to be evaluated. I think the function you want to use for general input from a user is raw_input().

Input() : http://docs.python.org/library/functions.html#input
raw_input(): http://docs.python.org/library/functions.html#raw_input
sharpe
sharpe

Hello, I've been getting into python and reading a book to get used to it, but I'm having some trouble understanding a part about while loops.


done = False

while not(done):

quit = input("Do you want to quit? ")

if quit == "y":

done = True;



attack = input("Does your elf attach the dragon?")

if attack == "y" :

print ( " Bad choice , you died . " )

done = True ;

Whenever I input anything into quit it just says that it wasn't defined, and when I try defining y like : y = "y" or something it doesn't actually quit. And this is straight from the book I am learning from.

And also, what books or tutorials would you recommend?

I'd highly recommend this Web site for learning the basics of Python: http://www.learn-to-program.net/

Also, see my thread: http://www.gamedev.n...game-in-python/


Here's a simple while loop (ignore white space):

option = 0

while option < 10:
option = option + 1
print "Inside the while statement until option is 10!"
print "Option is set to: ", option
raw_input()

print "\nOutside the while statement!"
print "Option is set to: ", option
print "Press enter to end the program."
raw_input()


Hope this helps!
A 30-year-old interested in learning to program by making an old-school, simple, text-only or 2D dungeon fantasy video game.

As of 9/28/2011, currently attempting to learn the basics of Python 2.7. As of 10/14/11, Dabbling in C#. As of 10/24/11, decisively surpassed my small knowledge of Python in C#.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.