Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Comparison Solution

why it didn't work???

name = input("Please enter your name: ") number = int(input("Please enter a number: "))

print("Hi {}".format(name)) print("Your number is {}".format(number))

is_fizz = number % 3 == 0 is_buzz = number % 5 == 0
is_fizzbuzz = number % 3 == 0 and number % 5 == 0

if number == is_fizz: print("{} is a fizz number".format(number)) elif number == is_buzz: print("{} is buzz number".format(number)) elif number == is_fizzbuzz: print("{} is a fizzbuzz".format(number)) else : print("{} not fizz and not buzz".format(number))

1 Answer

is_fizz, is_buzz, and is_fizzbuzz are boolean values and all you need for your if statements

name = input("Please enter your name: ")
number = int(input("Please enter a number: "))

print("Hi {}".format(name))
print("Your number is {}".format(number))

is_fizz = number % 3 == 0
is_buzz = number % 5 == 0
is_fizzbuzz = number % 3 == 0 and number % 5 == 0

if is_fizzbuzz:
  print("{} is a fizzbuzz".format(number))
elif is_fizz:
  print("{} is a fizz number".format(number))
elif is_buzz:
  print("{} is buzz number".format(number))
else:
  print("{} not fizz and not buzz".format(number))

Note: You should also check for is_fizzbuzz first to avoid false positives. For example 15 meets the condition of all three but should be recorded as a fizzbuzz number.