如何将输入结果打印到打印消息中?

时间:2019-11-29 01:29:56

标签: python

我试图在搜索中寻找它(除非我不知道描述它的正确方法)。

我的问题是我想知道如何从输入到打印消息中获得结果。例如,如果我对骰子的sum评分[在滚动5(1, 2, 3, 4, 5) = 15之后对25 extra points进行评分,然后对它进行评分会告诉我总分40 points。因此,我想知道如何将40分记入print message。我整天都在解决这个问题,所以任何开始的帮助都很棒。

2 个答案:

答案 0 :(得分:2)

亚历山大说的没错-很高兴看到您使用的工具。这是一个暂定示例,我认为这至少可以从一个起点谈起您遇到的问题:

arr1 = [1, 2, 3, 4]
total = sum(arr1)
print("the total is", total)

答案 1 :(得分:0)

您可以尝试以下方法:

user_input= [1, 2, 3, 4, 5]
extra_points = 25  

print('Your dice rolls are {} {} {} {} {}, for value, {}, with an extra points of {} for a total of {} points'.format(*user_input, sum(user_input), extra_points, sum(user_input) + extra_points)) 

输出为:

Your dice rolls are 1 2 3 4 5, for value, 15, with an extra points of 25 for a total of 40 points
相关问题