Numbers and booleans


How do i make a code so the programm recognize an integer number, a real number and a boolean? please help


An integer has no remainder when divided by 1…

if value % 1 == 0:
    # value is an integer

but first we need to determine if the value is a boolean primitive…

if type(value) == bool:
    # value is a boolean

When we get False from that, then we check if it is not a number:

if type(value) != int or type(value) != float:
    # value is not a number

if value % 1:
    # value is a float
    # value is an integer

There are multiple ways, so keep trying to solve this by some other means.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.