Is there any way that I can differentiate between these kind of flotes. ( x.00 and x.abc) | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
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)

15th May 2021, 11:49 AM
Ashutosh R. Yadav
Ashutosh R. Yadav - avatar
5 Réponses
0
Thank you guys Endalk and Lothar ... But I got an excellent ans. num == int(num) It gives True for x.00 type.. and False for x.abc type.
15th May 2021, 2:56 PM
Ashutosh R. Yadav
Ashutosh R. Yadav - avatar
+ 4
乡Ashutosh°^°Kumar乡 , you can use : if num % 1 == 0: if this expression is True, the float numbers fraction part is 0.
15th May 2021, 12:00 PM
Lothar
Lothar - avatar
+ 3
Endalk , take care with your current version. if the input number is 2.05, it will we seen like 2.0.
15th May 2021, 1:33 PM
Lothar
Lothar - avatar
+ 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
15th May 2021, 12:33 PM
Endalk
Endalk - avatar
+ 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
15th May 2021, 1:57 PM
Endalk
Endalk - avatar