您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python时间限制

Python时间限制

这是我的方法

import string
import random 
import time

response = "a"              # the variable that will hold the user's response
c = "b"                     #the variable that will hold the character the user should type
score = 0                   #the variable that will hold the user's score
start = time.time()         #the variable that holds the starting time
elapsed = 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
python 2022/1/1 18:41:38 有273人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶