Reputation: 49
I have to check if the input year is a a valid 4 digit no. Which isn't a float value or has more than 4 characters. The input is from a file dictionary type.
If not I want to exit the program and don't want to continue with the steps and functions after.
But the only challenge is I'm trying to do it without the use of libraries like sys etc. Is this possible in Python?
Upvotes: 0
Views: 141
Reputation: 1
You can check if the input is 4 digits or not by using input<10000 and input>999. You can check if the input is a float or not by using the type keyword. So, your program that you described would look something like this:
if x>999 and x<10000:
if type(x) != float:
print("Valid")
else:
print("Invalid")
else:
print("Invalid")
Hope this helps!
Upvotes: 0