这是我的方法:
import stringimport random import timeresponse = "a" # the variable that will hold the user's responsec = "b" #the variable that will hold the character the user should typescore = 0 #the variable that will hold the user's scorestart = time.time() #the variable that holds the starting timeelapsed = 0 #the variable that holds the number of seconds elapsed.while elapsed < 30: #while less than 30 seconds have elapsed if response == c: #if the response from the previous loop matches the character score += 1 #from the previous loop, increase the score. #c is a random character c = random.choice(string.ascii_lowercase + string.digits) print(c) response = input("Type a letter or a number: ") #get the user's response elapsed = time.time() - start #update the time elapsed
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)