Today I'm trying to make a python program by taking a float and an integer as one input at same time. But it shows some error.
This is what I have tried:
a=float,int(input("ENTER YOUR PERCENTAGE: "))
Today I'm trying to make a python program by taking a float and an integer as one input at same time. But it shows some error.
This is what I have tried:
a=float,int(input("ENTER YOUR PERCENTAGE: "))
Try this:
a = input()
a = float(a) if '.' in a else int(a)
From what i understand you want to get a float and integer both at the same time.
Try this code.Remember a
is stored as a tuple.Use the index to get the values stored in it.
a=float(input("ENTER YOUR PERCENTAGE AS FLOAT: ")),int(input("ENTER YOUR PERCENTAGE AS INT: "))
If you want to store them seperately all you have to do is this small change.
my_float, my_int=float(input("ENTER YOUR PERCENTAGE AS FLOAT: ")),int(input("ENTER YOUR PERCENTAGE AS INT: "))
I think this solution (though somehow cumbersome) does exactly what you want, provided you input two numbers:
a = [func(float(val)) for func, val in zip([float, int],
input("ENTER YOUR PERCENTAGE: ").split())]
Note: the above code needs the additional float(val)
inside func
to avoid an exception that raises if the string representing the second number (that will be cast to int) contains dot characters.