@python小程序 --指法练习
给娃熟悉键盘用的,在下面的小程序的基础上改的: https://blog.csdn.net/running_free/article/details/78255709 目前只包含字母键三行可打印的符号及空格,源码如下:
#!/bin/bash/python
#coding=UTF-8
from __future__ import division
import random
import string
print "**********欢迎来到打字练习软件,祝您玩的愉快!**********\n"
sample_strs = ['asdfghjkl;\'\\ASDFGHJKL',
'qwertyuiop[]QWERTYUIOP',
'zxcvbnm,./ZXCVBNM'
]
is_simple = True
def type_game():
while True:
flag=raw_input("继续(C)? 任意其他字符退出 : ")
flag=flag.lower()
if flag=="c":
#indicator=random.randint(3,30)
indicator = 24
example_list=[]
example_str=""
'''
for i in xrange(indicator):
num=random.randint(65,122)
# while num >= 91 and num <= 96:
# num=random.randint(65,122)
example_list.append(chr(num))
example_str="".join(example_list)
'''
for sample_str in sample_strs:
for count in range(1,6):
example_str=''
for i in range(int(indicator/4)):
if is_simple:
example_str += ''.join(random.sample(sample_str.lower(), 4)) +' '
else:
example_str += ''.join(random.sample(sample_str, 4)) +' '
str_len = len(example_str)-1
print "请快速输入以下",str_len,"个字母:",example_str
user_input=raw_input("请输入:")
if len(user_input)==0:
print "%d:输入为空,得了个鸡蛋OOOO"%j
else:
Correct_Num=0
myrange=min(len(example_str),len(user_input))
for j in xrange(myrange):
if user_input[j]==example_str[j]:
Correct_Num+=1
if len(user_input)>str_len:
print "%d:输入超限,扣10分,本次得分:%.2f"%(count,(Correct_Num/str_len)*100-10)
elif Correct_Num==str_len:
print "%d:完全正确,非常棒!"%count
else:
print "%d:本次得分:%.2f"%(count,(Correct_Num/str_len)*100)
else:
break
def main():
global is_simple
flag=raw_input("简单(J) or 复杂(F)? 任意其他字符退出 : ")
flag=flag.lower()
if flag=="f":
is_simple = False
elif flag != 'j':
return
type_game()
if __name__ == '__main__':
main()
|