+ 5
A basic python question (exceptions)
Hello all, I am trying to add an error so that no one will use a number for my input. How do I complete this program? Thank You!!! name =input("What is your name?") print("Hello", name) except IOError: print("An error has occurred")
4 Answers
+ 5
Except keyword means you have a try keyword.
So, write :
try:
name = input()
print("Hello", name)
except IOError:
print("Error")
+ 1
just do name = str(input(âWhat is your name?â))
+ 1
Make sure to catch the right exception. An input will probably never raise an IOError (which means that a file can't be read or the disk is full) and was replaced by OSError in some python 3.x version. Also, watch your indentation. Line 3 must not be indented whereas line 4 has to be indented
0
Try it with try statment.
try:
some code
except IOError:
other code