0
Is there any way that I can differentiate between these kind of flotes. ( x.00 and x.abc)
For example.. I want to separate flotes "which has zero after decimal point ( i.e. 2.0 , 7.0 , 12.0 etc)" and "which has some digits after decimal point. ( i.e. 5.32, 9.1432, 3.1 etc)
5 ответов
+ 4
乡Ashutosh°^°Kumar乡 ,
you can use :
if num % 1 == 0:
if this expression is True, the float numbers fraction part is 0.
+ 3
Endalk ,
take care with your current version. if the input number is 2.05, it will we seen like 2.0.
+ 1
You can treat them as strings. Eg.
x = str(2.0)
if x[x.index('.') +1] == '0':
print(x +' is x.00 type')
else:
print(x+' is x.abc type')
So, the output will be
# 2.0 is x.00 type
+ 1
Okay if that is the case you only add a colon to the code. Check this out
https://code.sololearn.com/c1DcQnZP7oQB/?ref=app