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

28th Jan 2019, 5:16 PM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
5 Antworten
+ 6
use 'is_integer' method (0.2).is_integer() #False (2.0).is_integer() #True
28th Jan 2019, 7:45 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 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!
28th Jan 2019, 5:41 PM
HonFu
HonFu - avatar
+ 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")
28th Jan 2019, 5:51 PM
Seb TheS
Seb TheS - avatar
+ 1
Seb TheS thanx. I am a beginner in python. I didn't know that I could use if else inside print. that's a new thing I learned. thanx again
28th Jan 2019, 6:13 PM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
0
HonFu my code is still working. can you plzz help me with the correct logic. thanx
28th Jan 2019, 5:45 PM
Nilutpol Kashyap
Nilutpol Kashyap - avatar