사용자 도구

사이트 도구


wiki:ai:python:타이핑_게임_제작_기본

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

다음 판
이전 판
wiki:ai:python:타이핑_게임_제작_기본 [2020/06/30 18:50]
hylee 만듦
wiki:ai:python:타이핑_게임_제작_기본 [2023/01/13 18:44] (현재)
줄 9: 줄 9:
  
 ===== 타이핑 게임 제작 (기본) ===== ===== 타이핑 게임 제작 (기본) =====
-==== 준비 사항 ====  +==== 준비사항 ====  
- +> 아래 파일을 받아 resource 폴더 안에 넣어주고 실행하면 됩니다.\\ 
-{{ :wiki:ai:python:word.zip |}}+{{ :wiki:ai:python:word.zip |}}\\ 
 +\\
 ==== 예제 코드 ====  ==== 예제 코드 ==== 
 <code python> <code python>
 +# Section13-1
 +# 업그레이드 타이핑 게임 제작
 +# 타이핑 게임 제작 및 기본완성
 +
 +import random
 +import time
 +
 +words = []                                   # 영어 단어 리스트(1000개 로드)
 +
 +n = 1                                        # 게임 시도 횟수
 +cor_cnt = 0                                  # 정답 개수
 +
 +with open('./resource/word.txt', 'r') as f:  # 문제 txt 파일 로드
 +    for c in f:
 +        words.append(c.strip())
 +
 +print(words)                                 # 단어 리스트 확인
 +
 +input("Ready? Press Enter Key!"            # Enter Game Start!
 +
 +start = time.time()                          # Start Time
 +
 +while n <= 5:                                # 5회 반복
 +    random.shuffle(words)                    # List shuffle!
 +    q = random.choice(words)                 # List -> words random extract!
 +
 +    print()
 +    print("*Question # {}".format(n))
 +    print(q)                                 # 문제 출력
 +   
 +    x = input()                              # 타이핑 입력 
 +
 +    
 +    if str(q).strip() == str(x).strip():     # 입력 확인(공백제거)
 +        print("Pass!")
 +        cor_cnt += 1                         # 정답 개수 카운트
 +    else:
 +        print("Wrong!")
 +
 +    n += 1                                   # 다음 문제 전환
 +
 +end = time.time()                            # End Time
 +et = end - start                             # 총 게임 시간
 +
 +et = format(et, ".3f"                      # 소수 셋째 자리 출력(시간)
 +
 +if cor_cnt >= 3:                             # 3개 이상 합격
 +    print("결과 : 합격")
 +else:
 +    print("불합격")
 +    
 +# 수행 시간 출력
 +print("게임 시간 :", et, "초", "정답 개수 : {}".format(cor_cnt))
 +
 +# 시작지점
 +if __name__ == '__main__':
 +    pass
  
  
줄 22: 줄 80:
 <code console> <code console>
  
 +Ready? Press Enter Key!
 +
 +*Question # 1
 +irs
 +irs
 +Pass!
 +
 +*Question # 2
 +displaying
 +s
 +Wrong!
 +
 +*Question # 3
 +roll
 +d
 +Wrong!
 +
 +*Question # 4
 +anyway
 +anyway
 +Pass!
 +
 +*Question # 5
 +zu
 +zu
 +Pass!
 +결과 : 합격
 +게임 시간 : 17.357 초 정답 개수 : 3
 </code> </code>
  
/volume1/web/dokuwiki/data/attic/wiki/ai/python/타이핑_게임_제작_기본.1593510650.txt.gz · 마지막으로 수정됨: 2022/03/10 19:52 (바깥 편집)