I have been wondering this for a longer time If I check for user input, I know how to check for strings. But what if I want to check if the user has entered just integers or floats. I tried it with an "if name == int or float: block but of course that didn't work. Can you help me out? How do I check for that? Here is my code. Of course the input I always converted to a string so I don't know how to do that.
print("Enter a name: ")
while True:
name = input()
if name != "":
print("Thank you for entering a name: ")
break
else:
print("Please enter a name: ")
I also tried this:
print("Enter a name: ")
while True:
name = input()
if type(name) != int:
print("Thats not a name!")
print("Now please enter a name without numbers")
elif type(name) != float:
print("Thats also not a name!")
print("Now please enter a name without numbers")
elif type(name) != "":
print("Thank you for entering your name!")
break
else:
print("Please enter a name: ")