我正在尝试创建一个函数,它包含一个列表,我给它我预测的比赛结果和我的赌注。因此,例如,我可以预测结果 [1,3,4,2],其中马 1 排在第 1 位,马 3 排在第 2 位,等等……这个预测将与随机/打乱列表 a 进行比较。我已经设置了几个 if 语句来尝试比较每个列表中的两个项目,但它最终让我所有的展示位置都是正确的,即使它们不是正确的。我卡住了!!!
def horseRace(gList,bet):
import random
a = [1,2,3,4]
random.shuffle(a,random.random)
i = 0
x = 0
while i < len(gList):
if gList[i] == a[0]:
x = x + 1
if gList[i] == a[1]:
x = x + 1
if gList[i] == a[2]:
x = x + 1
if gList[i] == a[3]:
x = x + 1
else:
x = x
i = i + 1
print(x)
print(a)
print(gList)
if x == 4:
money = bet*2
print("You guessed 4 position(s) correctly and won $ %d !"%money)
if x == 0:
money = 0.00
print("You guessed no position(s) correctly and won $ %d !"%money)
if x == 1:
money = bet
print("You guessed 1 position(s) correctly and won $ %d !"%money)
if x == 2:
money = bet
print("You guessed 2 position(s) correctly and won $ %d !"%money)
if x == 3:
money = bet
print("You guessed 3 position(s) correctly and won $ %d !"%money)