how to represent any whole number in python? Say if x == any whole number print(x)? How to represent this? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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
6 Respostas
+ 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