4 Réponses
+ 7
After you have done what @Dan said, the program itself raises the ValueError, you just need to except it. Try doing this: try: if int(x) % 2 == 0: print("The number is even.") elif int(x) % 2 == 0: print("The number is odd.") except ValueError: print("Please enter numbers and not letters.")
2nd Feb 2018, 6:04 PM
Dev
Dev - avatar
+ 4
Based on the error message, it's complaining that you have an end of line inside the string literal, put it all on one line or use string concatenation so that you don't have an end of line character in there
2nd Feb 2018, 6:02 PM
Dan Walker
Dan Walker - avatar
+ 1
no wait, set x to global value, or set x to local value. ##### #below local # x = int(input("num:")) def oe_local(localx): if localx... ... elif localx... ... else return None ##### #below global # x = int(input("num:")) def oe_global(): global x if x... ... elif x... ... else return None oe()
3rd Feb 2018, 1:01 PM
京空
京空 - avatar