首页 > 解决方案 > 用户输入后如何继续打印?

问题描述

from timeit import default_timer as timer
import random


num_1 = random.choice(range(12))
num_2 = random.choice(range(12))
score = 0

start = timer()


end = timer()


t = (end - start) # Time in seconds, e.g. 5.38091952400282


    
if t < 5 : 
    score += 100
if t > 5 :
    score += 50

print(score)

我如何再次打印输入???

就像我写了 6 * 8 之后,它给了我分数。我如何再次向用户询问问题???

标签: python-3.xmathrandom

解决方案


将输入放在 while 循环中:

num_1 = random.choice(range(12))
num_2 = random.choice(range(12))
score = 0

start = timer()


end = timer()


t = (end - start) # Time in seconds, e.g. 5.38091952400282

while True:
    
    ans = input("what is "+num1" * "+num2+"?")
    if t < 5 : 
        score += 100
    if t > 5 :
        score += 50

print(score)

推荐阅读