While loop replacing Else Statement?(Python) -


this question has answer here:

ok here

  done = false   while not done:       quit = input ("do want quit? ")       if quit == "y" :          done = true;        if not done:        attack = input ("does elf attack dragon? ")        if attack == "y":           print ("bad choice, died.")           done = true; 

but when to

           want quit? 

and enter

       n 

i

       traceback (most recent call last):          file "c:\users\your pc\desktop\jquery\dragon.py", line 4, in <module>            quit = input ("do want quit? ")          file "<string>", line 1, in <module>         nameerror: name 'n' not defined 

according http://www.youtube.com/watch?feature=player_embedded&v=2z2ph0ls9ew#! should work

input behaves differently in version 2 , 3 of python. you're on python 2, because tries interpret input in python environment.

you want raw_input() instead, reads in string.

edit: make difference clear, in python 2:

>>> type(input()) 0 <type 'int'> >>> type(raw_input()) 0 <type 'str'> 

in python 3:

>>> type(input()) 0 <class 'str'> 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -