build a python memory game. and i have done half of it . but I need help with th
ID: 3758690 • Letter: B
Question
build a python memory game. and i have done half of it . but I need help with the rest. plize if anyone can do this on python it would be great.
How many cards do you want to play with?
Enter an even number between 2 and 52:
Player: 5
Your program:
How many cards do you want to play with?
Enter an even number between 2 and 52:
Player: 6
Your program:
* * * * * *
1 2 3 4 5 6
Enter two distinct locations on the board that you want revealed.
i.e two integers in the range [1, 6]
Player: 1
2
Your program:
C B * * * *
1 2 3 4 5 6
Press enter to continue
Player: presses enter
Your program: clears the screen (so that the above board is not
visible) and prints
* * * * * *
1 2 3 4 5 6
Enter two distinct locations on the board that you want revealed
here is part of my program so far
import random
def create_board(size):
'''int->list (of str)
Precondition: size is even positive integer between 2 and 52
'''
board = [None]*size
letter='A'
for i in range(len(board)//2):
board[i]=letter
board[i+len(board)//2 ]=board[i]
letter=chr(ord(letter)+1)
random.shuffle(board)
return board
def print_board(a):
'''(list of str)->None
Prints the current board in a nicely formated way
'''
for i in range(len(a)):
print('{0:4}'.format(a[i]), end=' ')
print()
for i in range(len(a)):
print('{0:4}'.format(str(i+1)), end=' ')
def blanks(size):
'''['a','b','c','d']
[*,*,*,*]
'''
board = [None]*size
letter='A'
for i in range(len(board)//2):
board[i]=letter
board[i+len(board)//2 ]=board[i]
letter=chr(ord(letter)+1)
random.shuffle(board)
for i in range(len(board)):
board[i]="*"
return board
def wait_for_player():
'''(None)->None
Pauses the program until the user presses enter
'''
try:
input("Press enter to continue ")
except SyntaxError:
pass
def play_game(board):
'''(list of str)->None'''
board=create_board(size)
blank="*" * len(board)
discovered= [False]*len(board)
if size %2==0:
return("Your program: How many cards do you want to play with? Enter an even number between 2 and 52:")
b=int(input("player"))
elif size%2!=0:
print("Your program: How many cards do you want to play with? Enter an even number between 2 and 52:")
# The following line of code creates a list indicating what locations are paired, i.e., discovered
# At the begining none are, so default initializaiton to False is ok
# You may find this useful
discovered=[False]*len(board)
# YOUR CODE GOES HERE
# this is the funciton that plays the game
# MAIN
size=14
# YOUR CODE GOES HERE TOO
# HERE YOU OBTAIN THE SIZE OF THE BOARD THE PLAYER WANTS TO PLAY WITH
# once you are done remove size=14 above. I just did that so that this partial program should run
# this creates the board for you of the given size
board=create_board(size)
# this calls your play_game function that plays the game
play_game(board)
Explanation / Answer
def main():
board = []
for i in range(5):
board.append(-1)
win = False
mov = 0
while not win:
print_board(a)
print “Turn number “ + str(mov+1)
if mov % 2 == 0:
board= ‘X’
else:
board= ‘O’
user1 = play_game(board)
while board[user1] != -1:
print “Please try again later. ”
user = play_game(board)
board[user1] = 1 if board== ‘X’ else 0
size+= 1
if mov > 4:
winner = print_board(a)
if winner != -1:
out = “The winner is to “
out += if winner == 1 else “O”
out += "winner"
quit_game(board,out)
elif mov== 5:
quit_game(board,”There is No winner :(”)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.