Skip to content

Instantly share code, notes, and snippets.

@wsandin
Last active April 5, 2021 23:59
Show Gist options
  • Save wsandin/ca699b68ba19fbc4bb79a1a408264610 to your computer and use it in GitHub Desktop.
Save wsandin/ca699b68ba19fbc4bb79a1a408264610 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3.10
"""
Playing around with PEP 634: Structural Pattern Matching
introduced in Python 3.10. This is just a very simple attempt
at solving Fizzbuzz using a "case switch".
Read more at https://doc.python.org/3.10/whatsnew/3.10.html
"""
def fizzbuzz(num):
match num:
case _ if num % 5 == 0 and num % 3 == 0: print(f'{num} -> FizzBuzz')
case _ if num % 3 == 0: print(f'{num} -> Fizz')
case _ if num % 5 == 0: print(f'{num} -> Buzz')
case _: print(f'{num} -> None')
def main():
for n in range(1, 100):
fizzbuzz(n)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment