PRIMM 접근 방식을 사용하여 Python에서 Tic Tac Toe 게임 구축
내용물
Introduction
Stage 1: Predict
Stage 2: Run
Stage 3: Investigate
Stage 4: Modify
Stage 5: Make
프림을 만나다
PRIMM stands for Predict– Run–Investigate–Modify–Make, representing the different stages of a lesson or series of lessons. It enables critical thinking about how programs work, and the use of starter programs to encourage the reading of code before writing it.
1단계: 예측
구조화된 접근법
구조화된 접근 방식을 사용한다는 것은 각 코드 블록을 분석하고 함께 작동하는 방법을 결정해야 함을 의미합니다. 프로그램의 계층 구조를 결정하기 위해 구조 차트가 생성됩니다.
구조도를 이용하여 코드를 세분화한 후 코드의 기능에 집중할 차례입니다.
2단계: 실행
Copy the lines of code provided below and paste it in your python IDE and run it.
# import the extra functions
from time import sleep
from random import randint
# set the game rules
rock = 1
paper = 2
scissors = 3
name = {rock: "Rock", paper: "Paper", scissors: "Scissors"}
rules = {rock: scissors, paper: rock, scissors: paper}
player_score = 0
computer_score = 0
# start game and return score
def start():
print("Let's play TIC TAC TOE")
while game():
pass
return scores()
# the game func
def game():
player = play()
computer = randint(1, 3) # let the computer randomly between 1 and 3
outcome(player, computer)
return restart()
# let the player play
def play():
while True:
print()
player = input("Rock = 1\n Paper = 2\n Scissors = 3\n Kindly make a move: ")
try:
player = int(player)
if player in [1, 2, 3]:
return player
except ValueError:
pass
print("Please choose between 1, 2 or 3")
# the outcomes
def outcome(player, computer):
print("1....")
sleep(1)
print("2....")
sleep(1)
print("3...")
sleep(.5)
print("Computer threw {0}!".format(name[computer])) # string.format i.e use the computer choice to replace the {0}
global player_score, computer_score
if player == computer:
print("It's a Tie!!")
else:
if rules[player] == computer:
print("You're a genius")
player_score += 1
else:
print("You're being lectured by a computer")
computer_score += 1
# replay or restart func
def restart():
decision = input("Will you like to play again? Y/N: ")
if decision in ["Yes", "Y", "y", "yeah", "ofcourse"]:
return decision
else:
print("See you next time")
# the score func
def scores():
global player_score, computer_score
print("Final_score")
print("Player: ", player_score)
print("Computer: ", computer_score)
if __name__ == "__main__":
start()
예측 대비 확인
모든 것이 계획대로 진행되었습니까? 다음 단계로 진행하기 전에 코드를 모든 예측과 비교하십시오.
3단계: 조사
Trace each line of code and ensure that it functions as intended. You may explore how they function and learn more about the syntax by using python cheat sheet . trace table을 사용하여 프로그램을 추적하고 조건을 이해할 수도 있습니다. 따라서 각 코드 줄에 대해 토론하고 이에 대해 간단하고 간결한 설명을 작성하세요.4단계: 수정
Modify code in small steps to add new functionality. You can start by renaming the variables and functions, tweaking the code and applying what has been learnt about the structure of the code. Moreover, you can gradually increase the difficulty accordingly.
5단계: 만들기
Create a new but similar program to practice the programming skills that have been learnt.
요약 및 결론
PRIMM is a way of structuring programming
lessons that focuses on:
- Reading code before you write it
- Working collaboratively to talk about programs
- Reducing cognitive load by unpacking and understanding what code is doing
- Gradually taking ownership of programs when ready
참조:
PRIMM 접근법: 프로그래밍 수업을 구조화하기 위한 스캐폴드 접근법,
PRIMM은 학생들이 코드를 작성하기 전에 코드를 읽을 것을 권장합니다. 보낸 사람: The Big Book of Computing Pedagogy
https://www.101computing.net/using-trace-tables/
BBC Bitesize 가이드: 추적 테이블
https://www.bbc.co.uk/bitesize/guides/z8n3d2p/revision/8
구조도: https://press.rebus.community/programmingfundamentals/chapter/hierarchy-or-structure-chart/
Reference
이 문제에 관하여(PRIMM 접근 방식을 사용하여 Python에서 Tic Tac Toe 게임 구축), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/teach_wizbits/building-a-tic-tac-toe-game-in-python-using-primm-approach-4afn텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)