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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Christopher Morris](https://secure.gravatar.com/avatar/543cac79532eb2c4c54df8be3154b329?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Christopher Morris
iOS Development with Swift Techdegree Student 1,760 PointsCannot figure out why my elif are not working..
name = input("Please enter your name: ") number = int(input("Please enter a number: "))
TODO: Make sure the number is an integer*
TODO: Print out the User's name and the number entered,
making sure the two statements are on separate lines of output.
TODO: Compare the number the user gave with the different
FizzBuzz conditions.
*********************
If the number is divisible by 3, print "is a Fizz number."
If the number is divisible by 5, print "is a Buzz number."
If the number is divisible by both 3 and 5, print "is a FizzBuzz number."
Otherwise, print "is neither a fizzy or a buzzy number."
*********************
print(name,"\n", number) if (number / 3): print("{} is a Fizz number.".format(number)) elif (number / 5): print("{} is a Buzz number.".format(number)) elif (number / 3 & number / 5): print("{} is a FizzBuzz number.".format(number)) elif (number/3 or number/5): print("{} is neither a fizzy or a buzzy number.".format(number))
TODO: Define variables for is_fizz and is_buzz that stores
a Boolean value of the condition. Remember that the modulo operator, %,
can be used to check if there is a remainder.
Using the variables, check the condition of the value, and print the necessary
string
I tried using % and tried removing the parenthesis but no luck! I need help :(
1 Answer
![KRIS NIKOLAISEN](https://secure.gravatar.com/avatar/65d74a723997b41a80d2d909c6e06960?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
KRIS NIKOLAISEN
54,969 PointsYou'll want to use the modulo operator. In your code if (number / 3) is always true (except if number = 0 ) so the rest of the conditions are never considered.
One solution:
name = input("Please enter your name: ")
number = int(input("Please enter a number: "))
print(name,"\n", number)
if (number % 3 == 0):
if (number % 5 == 0):
print("{} is a FizzBuzz number.".format(number))
else:
print("{} is a Fizz number.".format(number))
elif (number % 5 == 0):
print("{} is a Buzz number.".format(number))
else:
print("{} is neither a fizzy or a buzzy number.".format(number))