0

I made a card flipping game if you want to learn how to play it go here https://www.youtube.com/watch?v=CCxs-tu8tOU

numbers = [0, 1, 0, 0, 1, 1, 0]

options = []

for num in range(0, len(numbers)):
    if numbers[num] == 1:
        options.append(num)

choice = int(input("Here's a list of cards: {}, your options are {}: ".format(numbers, options)))

The code below is too long and I need help simplifying it

if choice in options:
    numbers[choice] = '.'
    if numbers[choice-1] == 0:
        numbers[choice-1] = 1
    elif numbers[choice-1] == 1:
        numbers[choice-1] = 0
    if numbers[choice+1] == 0:
        numbers[choice+1] = 1
    elif numbers[choice+1] == 1:
        numbers[choice+1] = 0
  • Possible duplicate of [Is there a way to store a function in a list or dictionary so that when the index (or key) is called it fires off the stored function?](https://stackoverflow.com/questions/9205081/is-there-a-way-to-store-a-function-in-a-list-or-dictionary-so-that-when-the-inde) – Alessandro Da Rugna Oct 25 '19 at 17:26
  • 1
    if you only use 0 and 1, 1-numbers[choice+/-1] swaps 0 and 1. As the binary not operator also does in this case... – B. Go Oct 25 '19 at 19:17

0 Answers0