python-3.x - 用户输入后如何继续打印?
问题描述
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 之后,它给了我分数。我如何再次向用户询问问题???
解决方案
将输入放在 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)
推荐阅读
- python - 具有数值积分的函数图
- azure-devops - 如何在 yaml azure devOps 中运行 Windows bash 脚本的 if/else 步骤
- http - 加快读取 HTTP 响应正文以进行速度测试
- c - UDP网络实现的C语言中send()和sendTo()的区别
- php - 如何使用来自 Docker 的 Composer 通过 ssh 包含私有仓库
- android - Android 应用程序 - 无法绑定到 Android 11 上的 USB Tethering 端口 (rndis0) (EADDRNOTAVAIL)
- audio - 如何接收蓝牙音频信号并将其转发到蓝牙扬声器?
- python - Python Webscraping 列表项
- c# - 如何在条件查询中使用来自另一个列表的参数
- python - 在一个html表格中的产品下方显示产品属性?