'check if float is integer [duplicate]
I have a variable score wich increases over time I but would like to print only the integer ones. like 1.0, 2.0, 3.0 et cetera.
score += 0.5
if score.is_integer:
print(score)
But actually every score is printed.
0.5
1.0
1.5
2.0
2.5
3.0
3.5
4.0
4.5
5.0
5.5
6.0
6.5
7.0
7.5
8.0
8.5
9.0
9.5
What do I miss here?
Solution 1:[1]
if int(score) == score:
this should work fine or just follow the comment by @Robin Zigmond ie.,
if score.is_integer():
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Irfan wani |
