I am having trouble with coordinates and flipping the cards separately. This is my first time handling with coordinates in python.
When trying to flip the cards separately, the code registers the rows of cards as lists. I did use a list of lists to display the cards.
The code is shown below.
import random
wrong = 0
used = []
cards = deck()
def mmain():
random.shuffle(cards)
selected_cards = cards[:int(result / 2)]
selected_cards = selected_cards * 2
random.shuffle(selected_cards)
i = 0
while i < len(selected_cards):
row = selected_cards[i: i + columns]
i = i + columns
grid1.append(row1)
squares = [""]
grid = []
row = []
for i in range(rows):
row.append(squares)
for e in range(columns):
grid.append(row)
while True:
for i in range(len(grid)):
print(*grid[i])
squares = str(squares)
coordinate1 = int(input("Enter the first coordinate: "))
coordinate2 = int(input("Enter the second coordinate: "))
used.append(coordinate1)
used.append(coordinate2)
if coordinate1 in range(len(grid[i])):
for k in grid[i]:
k[coordinate1] = str(selected_cards[coordinate1])
elif coordinate2 in range(len(grid[i])):
for k in grid[i]:
k[coordinate2] = str(selected_cards[coordinate2])
elif selected_cards[coordinate1] == selected_cards[coordinate1]:
grid9 = "⬛"
grid10 = "⬛"
else:
wrong = wrong + 1
if grid[i] == "⬛":
print("You win! ")
print("Your score is: ")
break
mmain()
I would like help on this since I am struggling with it for weeks. I appreciate the answers to solve the problem. Thank you.
Note: I already have a program that helps displays the cards.
Edit: I am sure if someone helps me with this, the question I asked could help others.
Edit2: I use Google Colab for coding in python.