Hello - I am new to python and am attempting to validate that the user input is a number with my script. I have the below syntax, but instead of actually presenting my expected message, I get the below...
What do I need to change in my python syntax in order to get my desired error message?
What do I need to change in my python syntax in order to get my desired error message?
Error:Traceback (most recent call last):
File "<ipython-input-8-cfa0bf62612b>", line 1, in <module>
runfile('/home/owner/.config/spyder/temp.py', wdir='/home/owner/.config/spyder')
File "/usr/local/lib/python2.7/dist-packages/spyder_kernels/customize/spydercustomize.py", line 668, in runfile
execfile(filename, namespace)
File "/usr/local/lib/python2.7/dist-packages/spyder_kernels/customize/spydercustomize.py", line 100, in execfile
builtins.execfile(filename, *where)
File "/home/owner/.config/spyder/temp.py", line 24, in <module>
age = inputage("How old are you?")
File "/home/owner/.config/spyder/temp.py", line 16, in inputage
userInput = int(input(message))
File "/usr/local/lib/python2.7/dist-packages/ipykernel/ipkernel.py", line 176, in <lambda>
builtin_mod.input = lambda prompt='': eval(self.raw_input(prompt))
File "<string>", line 1, in <module>
NameError: name 's' is not defined
And this is the syntax that I am trying:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
def inputage(message): while True : try : userInput = int ( input (message)) except ValueError: print ( "Not an integer! Try again." ) continue else : return userInput break age = inputage( "How old are you?" ) if (age> = 18 ): print ( "You are over 18" ) else : print ( "You are under 18" ) |