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

FizzBuzz

hello guys im stuck in fizz buzz challenge, in my code i cant fulfill the fizzBuzz both condition is true . can u help me out with this othewise my code works.

name = input('Please enter your name: ')
number = int(input('Please enter your number: '))
is_fizz = number % 3 == 0
is_buzz = number % 5 == 0
is_FizzBuzz = number % 3 == 0 and number % 5 == 0
print('Hey {}! '.format(name))
print('The number ', number, '...')
if is_fizz:
    print('is Fizz number')
elif is_buzz:
    print('is Buzz number')
elif is_FizzBuzz:
    print('is FizzBuzz')
else:
    print('is neither a Fizzy or Buzzy number')

[MOD: added ```python formatting -cf]

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,426 Points

Hey Pawan Sanwlot, you are very close. In the code, If is_FizzBuzz is True then either is_fizz or is_buzz will also be True causing one of the earlier conditions to match before the FizzBuzz condition matches. A reordering of the if conditions should do the trick.

Post back if you wish more detailed help. Good luck!!

Thanks Chris!