Python Help

Started by
2 comments, last by sharpe 12 years, 6 months ago
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?
Advertisement
free ebook
diz is a pretty kewl ebook!
That was the time, the Golden Age, when C-64 and Amiga ruled!

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

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

This topic is closed to new replies.

Advertisement