카드짝맞추기 코드좀 도와주세요
본문
빈칸 채워야하는데 파이썬 완전 초보입니다.. 도움 주시면 감사하겠습니다 ㅠㅜ..
from cs1graphics import * from time import * import random canvas = Canvas(640, 580) canvas.setTitle("Memento") path = "./images/" names = ("1.jpg", "2.jpg", "3.jpg", "4.jpg", "5.jpg", "6.jpg") ##가로 90pixel, 세로 120 pixel jpg 파일을 불러오세요. cards = [] # jpeg 이미지 num_pads = [] # 숫자 0~23 correct_list = [] # 맞춘 카드 리스트 tries = 1 # cards initialization def initialize(): for i in range(6): for k in range(4): img = Image(path + names[i]) temp_tuple = (img, names[i]) cards.append(temp_tuple) for i in range(24): card = Layer() rect = Rectangle(90, 120, Point(0, 0)) text = Text(str(i), 18, Point(0, 0)) card.add(rect) card.add(text) num_pads.append(card) # 2-2-1. shuffle the card list random.shuffle(cards) def print_cards(): canvas.clear() w = 0 h = 0 i_w = 70 i_h = 90 for i in range(len(num_pads)): # 2-2-2. rewrite the condition for visualization. if i in correct_list: cards[i][0].moveTo(i_w + w, i_h + h) canvas.add(cards[i][0]) else: num_pads[i].moveTo(i_w + w, i_h + h) canvas.add(num_pads[i]) w += 100 if w % 600 == 0: w = 0 h += 130 def is_valid(num1, num2): # YOUR CODES # 2-1-1. check if any of two numbers exists in the current correct list or are same number. # return boolean value according to the result. def check(num1, num2): # YOUR CODES # 2-1-2. at first, visualize the screen including the two cards(num1-th card and num2-th card). # if two numbers of two cards are same, put two numbers into the correct list. # if not, re-visualize the original screen. # return boolean value according to the result. initialize() # YOUR CODES # 24개의 모든 그림을 보여준다. # 초기에 correct_list에 24개의 모든 그림을 넣어 구현할 수 있을 것이다. sleep(3) # 이제 게임을 시작해야 하므로 correct_list 를 모두 비운다. correct_list = [] print_cards() print("### Welcome to the Python Memento game!!! ###") # 2-2-3. rewrite the condition for termination # YOUR CODES # while 문을 사용하여 모든 카드를 맞출 때까지 게임을 계속한다. # 한번 시도할 때 마다 tries 를 높인다. sleep(1)
답변 2
초보시면 초급단계부터 시작하시기 바랍니다.
심화과정에서 본인 실력을 키우기 위한 문제같은데,,,
해당 문제를 모른다면 앞부분을 다시 공부하시고 직접 해결하시는게 좋아보이네요,,,
오지랖일지모르지만
답변을 작성하시기 전에 로그인 해주세요.