I was wondering if it was possible to specify the type of input in a function or if I had to use something else.
Imagine that I defined a function (example). I want my parameter (type) to indicate what type the input will be as if
int(input())
If it's not an int, I send an error and I ask again for an input.
def example(type) :
while True :
try :
var = type(input())
except :
print("error")
else :
break
return var
example(int)
I don't know if it's possible. Eventually, I want to do it for floats and strings. I bypassed the problem with if / else. Do you have other solutions? I want to shorten my code as much as possible.