1

I tried to write a simple fizzbuzz program in python, I tried to use isinstance to determine if a number is a float or a int instead of creating a list, but whenever I try it for some reason it considers every number to be a float is this a thing in python or a flaw in my logic?

i = 3
if isinstance(i/3,float) == False:
    print("Fizz")
else:
    print("???")
Mureinik
  • 297,002
  • 52
  • 306
  • 350
Zaper
  • 23
  • 4

1 Answers1

1

The / operator returns a float. Even if the value could be expressed by an integer, you'll still get a float. E.g., 3/3 will return the float value of 1.0. Instead, you could check the remainder directly using the % operator:

if i % 3 == 0:
    print("Fizz")
else:
    print("???")
Mureinik
  • 297,002
  • 52
  • 306
  • 350