Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialOleg Tiger
388 Pointswhy 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
KRIS NIKOLAISEN
54,971 Pointsis_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.