On 21/04/14 19:12, Stephen Mik wrote:
...I am inputting or trying to input,a Sentry Variable to a While Loop. I want to test out the Main program" While" Loop before I add an inner "While" Loop. The program I have written,when run on the Python 3.4.0 Shell,does not stop for input of the "While" Sentry Variable,it just gives a program error: "Value of smv_grandVariable undefined". What am I doing wrong here?
> import random > ... > print("Do you want to play the game?\n") > print("Enter a 1 to play or 0 to exit:") > input(smv_grandVariable) You have completely misunderstood input... input takes as an argument a prompt string and returns the value input by the user so your usage should look like: smv_grandVariable("Enter a 1 to play or 0 to exit:") But that's a terrible name for a variable. You should name variables after their purpose. What does this variable represent? You say its a sentry? So call it sentry... Having the word "variable" in a variable name is nearly always a mistake. > while (smv_grandVariable == 1 and smv_grandVariable != 0): And your second mistake is that you have not converted the string typed by the user to a number(specifically an int) but you are comparing the variable to the numbers 0,1 Finally the logic of your test can be replaced by the simpler while int(smv_grandVariable) != 0: since 1 is also not zero. HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor