Last active
April 5, 2021 23:59
-
-
Save wsandin/ca699b68ba19fbc4bb79a1a408264610 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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