Sign in to follow this  
Sx2Kirby

Python Help

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.

[code]
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 ;
[/code]
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
[quote name='Sx2Kirby' timestamp='1318622791' post='4872651']
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.

[code]
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 ;
[/code]
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?
[/quote]



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() : [url="http://docs.python.org/library/functions.html#input"]http://docs.python.org/library/functions.html#input[/url]
raw_input(): [url="http://docs.python.org/library/functions.html#raw_input"]http://docs.python.org/library/functions.html#raw_input[/url]

Share this post


Link to post
Share on other sites
[quote name='Sx2Kirby' timestamp='1318622791' post='4872651']
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.

[code]
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 ;
[/code]
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?
[/quote]
I'd highly recommend this Web site for learning the basics of Python: [url="http://www.learn-to-program.net/"]http://www.learn-to-program.net/[/url]

Also, see my thread: [url="http://www.gamedev.net/topic/611809-seeking-beginner-advice-for-text-only-dungeon-game-in-python/"]http://www.gamedev.n...game-in-python/[/url]


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

[code]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()
[/code]

Hope this helps! :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this