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 trial

Python

Lucas Garcia
Lucas Garcia
6,612 Points

FizzBuzz Challenge

Why aren't any of my if statements printing? When I run this the only thing that prints is the input for the user name and number entered. Thank you for your help!

name = input("Please enter your name: ") number = int(input("Please enter a number: ")) is_fizz = (number % 3 == 0) is_buzz = (number % 5 == 0) print("Your name is {}".format(name)) print("The number you entered is {}".format(number))

if number == is_fizz: print("{} is a Fizz number".format(number)) if number == is_buzz: print("{} is a buzz number".format(number)) if number == (is_fizz & is_buzz): print("{} is a FizzBuzz number".format(number))

This condition if number == is_fizz: will always return False because your is_fizz and is_buzz are booleans, meaning either True or False.
But number is expected to be... well, a number, so nothing is printed.

1 Answer

Lucas Garcia
Lucas Garcia
6,612 Points

Thank you Pierre Guiglion. I got it to work!

name = input("Please enter your name: ") number = int(input("Please enter a number: ")) is_fizz = (number % 3 == 0) is_buzz = (number % 5 == 0) is_fizzBuzz = ((number % 3 == 0) & (number % 5 == 0)) is_neither = ((number % 3 != 0) & (number % 5 != 0)) print("Your name is {}".format(name)) print("The number you entered is {}".format(number))

if is_fizzBuzz == True: print("{} is a FizzBuzz number".format(number)) elif is_fizz == True: print("{} is a Fizz number".format(number)) elif is_buzz == True: print("{} is a buzz number".format(number)) elif is_neither == True: print("{} is neither a fizzy or a buzzy number".format(number))