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 trialAdam Kroner
1,460 PointsComparison Solution Help
I think this almost works but I do not understand why it always prints my else statement?
name = input("Please enter your name: ") number = input("Please enter a number: ")
number = int(number)
print("Hello{},\nthe number {}...".format(name, number))
if number % 3 == 0: print("is a Fizz number.") if number % 5 == 0: print("is a Buzz number.") if (number % 3) + (number % 5) == 0: print("is a FizzBuzz number.") else: print ("is neither a fizzy or a buzzy number.")
2 Answers
Steven Parker
231,198 PointsWhen posting code, you need to use Markdown formatting to preserve the appearance (particulary indentation); and without seeing the indentation it's impossible to predict how the code might behave.
But two issues visible as it is:
- tests in a chain (after the first one) should use "elif" instead of "if"
- a compound condition ("FizzBuzz") must be tested before the individual conditions
Adam Kroner
1,460 PointsHeard sir I will try those, apologies on the construction in the question. It appeared alright when I copy and pasted but I did not check what it looked like on the forum.