我正在开发一个程序,它将选择多个用户的赢家并显示获胜者。我已经计算了百分比数,它将是用户名将附加到列表的次数。
澄清:
到目前为止我的代码:
probabilities = []
print("Calculating", player1 + "'s luck!")
time.sleep(3)
player1num = random.randint(0,100)
newnum = player1num / 2
newnumadded = newnum + 10
if newnumadded > 50:
bonusnum = newnumadded + 25
print(player1 + " Your number is:", str(player1num) + "! You have a percentage to win of: ", str(bonusnum) + "%!")
else:
print(player1 + " Your number is:", str(player1num) + "! You have a percentage to win of: ", str(newnumadded) + "%!")
我试图让它成为player1变量(这是用户名)将存储在概率列表中与百分比数相同的次数。
示例:John,有一定几率赢得79%的胜利。将John添加到列表中79次
答案 0 :(得分:1)
如果您想将player1
添加到列表percentage_list
,您可以执行percentage_number
次{/ p>}次
percentage_list.extend([player1] * percentage_number)
答案 1 :(得分:0)
只需在列表中附加x元素x次:
[