• Advertisement
Sign in to follow this  

Python Help

This topic is 2320 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement

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

Share this post


Link to post
Share on other sites

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! :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement