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 trialFrances Angulo
5,311 PointsWent 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.")
1 Answer
Nicolai Christensen
2,996 PointsI 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!
Jeff Muday
Treehouse Moderator 28,720 PointsJeff Muday
Treehouse Moderator 28,720 PointsI 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.