问题: 安东尼娅和大卫在玩游戏。 每个球员从100分开始。 这个游戏使用标准的六边形骰子,分回合进行。在一轮比赛中,每个选手 掷一个骰子。低掷骰子的玩家失去高骰子上显示的点数。如果 两个牌手掷同一个号码,任何一个牌手都不会丢分。 写一个程序来确定最后的分数。
输入规范 输入的第一行包含整数n(1≤n≤15),即 将被播放。在接下来的n行中,每行都是两个整数:那一轮的安东尼娅掷骰子, 接着是空格,接着是那一轮的大卫掷骰子。每次掷骰都是整数 介于1和6之间(包括1和6)。 输出规格 输出将由两行组成。在第一行,输出Antonia拥有的点数 在所有回合结束后。在第二行,输出David拥有的点数 在所有回合结束后。
我的许多问题之一是使程序列出第一个输入指定的正确输入数。
以下是我目前所掌握的情况:
rounds = input()
score1 = input()[0:3]
score2 = input()[0:3]
score3 = input()[0:3]
score4 = input()[0:3]
game = [score1, score2, score3, score4]
antonia = 100
david = 100
for scores in game:
roll = game
a = game[0]
d = game[2]
if a > d:
antonia -= int(d[0])
elif d < a:
david -= int(a[2])
elif a == d:
break
print(antonia)
print(david)
我知道我只要求了一件事,但是有人能完成这个挑战并解释一下最好的方法吗?
显然,我不会为您解决这个类似于家庭作业的任务,而是执行
} 一样:
n
轮(在您的情况下n = rounds
)您应该使用for
循环,就像在程序中使用^{这将执行
rounds
次(0
…rounds-1
)。并且i
将是索引。在一种方法:
这是我最新的回答:
基本上,当你不知道你有多少次迭代(你不知道循环的数量,你只知道它在1到15之间,我还没有解释),你应该使用类似
while i<nr of rounds
,或者我们的同事告诉你for i in range(rounds)
。在另外,无论何时接受输入,都应该使用原始的输入而不是输入(在python2.7中)。我不认为
[0,3]
在score1 = input()[0:3]
中是必要的。在相关问题 更多 >
编程相关推荐