レースの予想結果と賭けのリストを受け取る関数を作成しようとしています。したがって、たとえば、馬 1 が 1 位、馬 3 が 2 位などの結果 [1,3,4,2] を予測できます。この予測は、ランダム化/シャッフルされたリストと比較されます。各リスト内の両方のアイテムを相互に比較するためにいくつかの 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)