[파이썬 실습] 랜덤 타자 게임 만들기 - while, random, time

파이썬 실습 '타자 게임'

따라 쓰는 타자 게임을 만들어 보겠습니다.
타자 게임은 반복문(while문)을 사용합니다.



*****
while문의 기본 구조

while <조건문>:
<수행할 문장1>
<수행할 문장2>
<수행할 문장3>
...
*****

01. 모듈 불러오기

import random
import time

02. 문제 리스트 만들기

word_list = ['강아지','고양이','코끼리','원숭이','하마','기린']
num = 1

03. 랜덤하게 나오는 단어를 얼마나 빨리 맞췄는지 확인

print('[타자게임] 준비되었다면 엔터를 쳐주세요!')
input()
start = time.time()

word = random.choice(word_list)

while num <= 3:
print("*문제",num)
print(word)
input_word = input()
if word == input_word:
print("통과!" + "\n")
num = num + 1
word = random.choice(word_list)
else:
print("잘못 입력하셨습니다. 정확하게 입력해 주세요!" + "\n")
end = time.time()
total_time = end - start
total_time = format(total_time, ".2f")

print("타자시간:", total_time, "초")




댓글

이 블로그의 인기 게시물

[python] 1. 파이썬 라이브러리 설치 및 버전확인

[python] 4. 파이썬 파일 불러올때 설정 (데이터양, 인덱스 설정)