我想每次将用户输入增加 1,以便显示输出
根据用户开始时输入的游戏数量,重复此提示, 无论如何,这可能是一个简单的解决方案,但似乎无法正确解决,我是新手:) 如有任何帮助,TIA 将不胜感激
n = int(input("enter total number of games "))
games = []
for i in range(n):
x = int(input("score for game 1 ")) #this line!#
games.append(x)
print("total Points is ", sum(games))
average_score = sum(games) / n
if average_score <=15:
print("Average Score per game is ",round(average_score, 2) , "really poor! better luck next time")
elif average_score >= 16 and average_score <=18:
print("Average Score per game is ",round(average_score, 2), "Well done!")
else:
print("Average Score per game is ",round(average_score, 2), "Amazing result, you could be top 3! ")
我尝试在附加中添加增量。但这不起作用
不要尝试手动递增任何内容 - 因为您在
for
上使用 range
循环,所以您可以使用迭代变量 (i
) 的值作为“递增”变量。您必须将范围从 [0, n-1] 调整为 [1, n],您可以在 for
语句中执行此操作。然后您可以使用 f 字符串进行实际打印;这是在字符串中使用 int 变量的最简洁且(对我来说)最易读的方式。
n = int(input("enter total number of games "))
games = []
for i in range(1, n+1):
x = int(input(f"score for game {i} ")) #this line!#
games.append(x)