+ 2

how to represent any whole number in python? Say if x == any whole number print(x)? How to represent this?

29th Jun 2020, 9:19 PM
3.14
3.14 - avatar
8 Answers
+ 2
if x>0 and x%1==0: print(“x”)
1st Jul 2020, 10:32 AM
Pr0C0d3r
Pr0C0d3r - avatar
+ 3
if x % 1 == 0 and x >= 0: print(x, "is whole number.")
29th Jun 2020, 9:25 PM
Seb TheS
Seb TheS - avatar
+ 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.
30th Jun 2020, 5:36 AM
Seb TheS
Seb TheS - avatar
+ 3
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 The page didn't say a whole number couldn't be negative. Edit, now it did.
30th Jun 2020, 5:56 AM
Seb TheS
Seb TheS - avatar
+ 1
if isinstance(x, int): print(x, 'is a whole number')
29th Jun 2020, 9:31 PM
Slick
Slick - avatar
+ 1
if int(x) == x: print("whole number")
30th Jun 2020, 7:56 AM
arieh