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

I did it pretty diffrent but it works

My code is somewhat diffrent but works.. is it still a valid way to do the challange or am i messing up ?

name = input("Please enter your name: ") number = int(input("Please enter a number: ")) print("Hi {} Hope you enjoy the game!".format(name)) print("The number you selected was {}".format(number))

def is_fizz(number): if number%3==0: return True else: return False

def is_buzz(number): if number%5==0: return True else: return False

if is_buzz(number) == True and is_fizz(number) == True: print("its a Fizzbuzz number") elif is_buzz(number) == True: print("its a buzz number") elif is_fizz(number) == True: print("its a fizz number") else: print("is neither a fizzy or a buzzy number")

1 Answer

Steven Parker
Steven Parker
229,982 Points

It's typical that as programs get more complex, there will be more ways to achieve the same result. There is rarely a single "right" way. But in addition to doing the job, you can always shoot for making the code easy to read and maintain, efficient in execution, and concise and compact.

This code looks fine as-is (good job! :+1:), but here's some tips for making it a bit more compact:

You never need to compare a boolean with "True". For example:

if is_buzz(number) == True:  # comparison is not needed
if is_buzz(number):          # just test directly!

You also don't need to test a comparison just to return a True or False:

def is_buzz(number):
    return number % 5 == 0   # just return the comparison itself

Keep up the good work, and happy coding!