I am having an issue with Python validation. I was wondering if there was a simple way to put validation on two input numbers to check a few things:
If the inputs are ints
if neither of the inputs equals a certain number, they are not valid. (For example, this would mean one of them would have to be 5. So a = 1
b = 4
, a = 3
b = 2
, a = 1
b = 1
wouldn't work)
If the two numbers are the same number that is required it will not work (E.G. if a = 5 b = 5 will not work as 5 is the required number, however a = 1 b = 5 would work as 5 is only being inputted once).
while True:
a = input("Enter first input: ")
b = input("Enter second input: ")
try:
val = int(a)
val1 = int(a)
if val1 != 5 or val != 5:
print("I'm sorry but it must be a pos int and equal 5")
continue
break
except ValueError:
print("That's not an int")
This is what I was trying to do, but I think I may be dreadfully wrong?
Any help appreciated!
Thanks.