我正在開發一個程序,該程序將選擇多個用戶的獲勝者並顯示獲勝者。我計算了百分比數字,這將是用戶名將追加到列表的次數。多次將相同的項目添加到列表中
澄清:
- 計算百分比
- 追加使用者名稱到列表的時間相同數量的百分比數。
- 從列表中選擇一個隨機的人。
- 顯示贏家。
繼承人到目前爲止我的代碼:
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變量(也就是用戶名)將存儲概率的內列出相同的次數作爲百分比數字。
例如:約翰,有一個百分比勝率79%的機會。加入約翰名單79倍
或此:http://stackoverflow.com/questions/9259989/select-random-item-with-weight或甚至可能:http://stackoverflow.com/questions/3679694/a-weighted-版本的隨機選 – Lafexlos