[Python/파이썬] 간단한 타자연습 프로그램 만들기

2019. 11. 6. 14:31Python

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from random import *
import time
 
= open("all.txt""rt")
 
l1 = f.readlines()
l2 = []
for i in l1:
    l2.append(i[:-1])
 
shuffle(l2)
start = time.time()
= input(l2[0]+"\n")
if( x == l2[0]):
    print("correct!")
else:
    print("wrong!")
end = time.time()
dur = end-start
res = (len(l2[0])/dur) * 60
print("Time : %.2f, Result : %.2f" %(dur, res) )
 
cs

 

위 코드와 동일한 파일 경로에 all.txt 예문을 생성하고 코드를 실행시키면 된다.

all.txt 안에 다음 문장들을 예문으로 추가하였다.

 

Where am I?
What time is it now? It is a quarter past nine by my watch.
You will not be able to persuade that obstinate man.
You will have to submit to your fate whether you will or not.
Will you have time enough to do this for me tomorrow?
How much will you need? I will need two thousand won

 

 

541타가 나왔다. 평소의 내 영타 속도와 얼추 비슷하다.

 

다음에 발전시킬 수 있는 것 : 예문 추가하기, 정확도 %로 만들어 출력하기, 프로그램 계속 실행시키기, 장문 타자 연습