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
Lucas Garcia
6,612 PointsFizzBuzz 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))
1 Answer
Lucas Garcia
6,612 PointsThank 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))
Pierre Guiglion
11,583 PointsPierre Guiglion
11,583 PointsThis condition
if number == is_fizz:will always returnFalsebecause youris_fizzandis_buzzare booleans, meaning eitherTrueorFalse.But
numberis expected to be... well, a number, so nothing is printed.