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 Comparison Challenge

Is there is way to make this cleaner?

is there a way to make this any cleaner? or to make "if is_fizz and is_buzz" be the last option on the list? or does it have to be the first one?

Edit, how do i add a screenshot of my work?

https://w.trhou.se/6m4704limq

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

To link to an image, save the image at an external URL, say, on Imgur. Then link to image use the format ![alt text](/path/to/img.jpg "Title")

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

You code is as straightforward as can be expected. The if/elif/else is the only choice for now.

Coming in Python 3.10, there will be a match/case statement as defined in PEP 634.

match (number % 3 == 0, number % 5 == 0):
    case (True, False):
        print(f"{number} is Fizz")
    case (False, True):
        print(f"{number} is Buzz")
    case (True, True):
        print(f"{number} is FizzBuzz")
    case _:
        print(f"{number} is neither Fizz nor Buzz")