Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Comparison Solution

Frances Angulo
Frances Angulo
5,311 Points

Went a different route but think it works?

It looks like I did this largely in logic and didn't use any variable concepts. Is what I've done less scalable, stable, or transferrable to new applications? Are there benefits to using a variable driven approach?

name = input("Please enter your name: ") number = int(input("Please enter a number: "))

print("Hello {}!" .format(name)) print("The number {}..." .format(number))

if number % 5 == 0 and number % 3 == 0: print("is a FizzBuzz number.") elif number % 3 == 0: print("is a Fizz number") elif number % 5 == 0: print("is a Buzz number") else: print("is neither a fizzy or a buzzy number.")

(I modified the question to code-format)

name = input("Please enter your name: ")
number = int(input("Please enter a number: "))

print("Hello {}!" .format(name)) print("The number {}..." .format(number))

if number % 5 == 0 and number % 3 == 0:
    print("is a FizzBuzz number.")
elif number % 3 == 0:
    print("is a Fizz number")
elif number % 5 == 0:
    print("is a Buzz number")
else:
    print("is neither a fizzy or a buzzy number.")
Jeff Muday
Jeff Muday
Treehouse Moderator 27,510 Points

I like it! Definitely shows you know conditional blocks and the order of operations.

Keep posting code that you enjoyed or did something cool and different. Super-great for others who are having trouble demonstrating that there are MANY clever and creative ways to solve coding challenges.

By the way, this type of question (the fizz-buzz-bazz) is often asked at entry level developer interviews. It weeds out the serious from the non-serious candidates.

Good luck with your Python journey.

1 Answer

Nicolai Christensen
Nicolai Christensen
2,996 Points

I had the same approach as you did Frances Angulo. I realized that the better approach was the course sollution. Not having to change the code too many places if you want it to check for example the numbers 6 and 9 instead. By our approach you need to change it in 4 lines. In the suggested course sollution you only need to change it in 2 lines. Imagine a case with several thousand lines!