def draw_selected_pattern_forever(choice): if (choice == 1): Patterns.blinker().draw_matrix_forever() elif (choice == 2): Patterns.toad().draw_matrix_forever() elif (choice == 3): Patterns.beacon().draw_matrix_forever() else: raise ValueError("there is no suitable pattern for the given number")
# review: I'd probably cast the choice into an int and check the `if` statement against the singleton value of the int. This is a bit more consistent with PEP 8 # http://www.python.org/dev/peps/pep-0008/#programming-recommendations # For example # choice = int( choice ) # if choice is 1: # ... # # review: consider moving this logic to a more generic method that will allow running the game separately from the `main` block # (for example via the interteractive shell) if (choice == '1'): Patterns.blinker().draw_matrix_forever() elif (choice == '2'): Patterns.toad().draw_matrix_forever() elif (choice == '3'): Patterns.beacon().draw_matrix_forever() else: # review: consider re-using this block of code to a separate method as it's used in the `catch` block as well print('bye...') # review: you didn't import sys, interrupting causes an error: # NameError: name 'sys' is not defined sys.exit() except KeyboardInterrupt: # review: not sure if this is really needed, as you don't do any resource cleanups here, so maybe it's best to just # let the exception propogate. Not sure. print('bye...') sys.exit()