0
Can any1 pls check if this code is correct?
can it be more simplified? I need to check whether a given number is integer or float https://code.sololearn.com/cn548poTePw0/?ref=app
5 Antworten
+ 6
use 'is_integer' method
(0.2).is_integer() #False
(2.0).is_integer() #True
+ 2
Your a will always be float (since you turn it into one) except you can't float the input in the first place.
Your b will always be an int, because you use //. And if you used / it would always be a float, since Python will give you a float whenever you divide.
So this is not yet the way to solve your task!
+ 1
Not much, only shortened, what you did worked and was very readable. Another way is to change the user input to integer.
a=float(input())
b=int(a)
print("integer" if a==b else "float")
0
HonFu my code is still working. can you plzz help me with the correct logic. thanx