I am taking in intro CS course and am playing around with some of my old code from an early lab. The program asks for four separate inputs from the user and will then spit out a graph according to the four inputs. I'm trying to get it where if the user does not enter a number then it asks for them to try again and prompt for another input. I've tried things like: (if x != int:) and (if x =\= int:) but nothing has worked for me.
Asked
Active
Viewed 159 times
1 Answers
-4
You could do something like this:
userInput = 0
while True:
try:
userInput = int(input("Enter an integer: "))
except ValueError:
print("Not an integer!")
continue
else:
print("Yay an integer!")
break

bhazero025
- 337
- 4
- 15
-
This doesn't work. For example, if I enter `1.5`. It works. But `1.5` is not an integer. – RobertB Jan 27 '17 at 01:10