+ 2
how to represent any whole number in python? Say if x == any whole number print(x)? How to represent this?
8 Answers
+ 2
if x>0 and x%1==0:
print(“x”)
+ 3
if x % 1 == 0 and x >= 0:
print(x, "is whole number.")
+ 3
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 Are you sure that a whole number can't be negative? I have always though whole number is a synonym for integer, which can be negative.
+ 3
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 The page didn't say a whole number couldn't be negative.
Edit, now it did.
+ 1
if isinstance(x, int):
print(x, 'is a whole number')
+ 1
if int(x) == x:
print("whole number")