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

Any tips on solving FizzBuzz in Python?

Question :

Based on a traditional English children's game

Print the numbers 1..100

For multiples of 3, print "Fizz" instead of the number

For multiples of 5, print "Buzz" instead of the number

For multiples of 3 and 5, print "FizzBuzz" instead of the number

Link to workspace

https://w.trhou.se/5nbz0nrrr7

Currently I'm trying to solve using conditional step approach, still new to this but thought I'd give the problem a shot.

What concepts should I review?

What variable are missing?

Am I lacking understanding of the question?

2 Answers

Aaron Nolan
Aaron Nolan
5,714 Points

Hey Benji! Your answer is technically correct but you're making one simple mistake.

Tab spacing in Python is actually very important to Python. It can be whatever you like but it needs to be consistent. Unfortunately right at the end of your program your else statement is tabbed out too far and thats what is causing your problem. So just correct the spacing like so and it will work perfectly! Hope this helps and happy coding :)

for x in range(1, 101):
    if x % 3 == 0 and x % 5 == 0:
        print("FizzBuzz")

    elif x % 3 == 0:
        print("Fizz")

    elif x % 5 == 0:
        print("Buzz")

    else:
        print(x)

Hi Aaron, Following your advice, I corrected the spacing and it runs in now! Thanks again for the help in troubleshooting / solving. Happy coding to you as well!