Python random horserace
I'm trying to create a function where it takes in a list I give it of my
predicted out come of the race and my bet. So for example, i could predict
the outcome [1,3,4,2] where horse 1 would be in 1st, horse 3, in 2nd
etc... This prediction would be compared to a randomized/ shuffled list a.
I have set up a couple of if statements to try and compare both items in
each list to each other but it ends up giving me all my placements were
correct even if they were not. I am stuck!!!
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)
No comments:
Post a Comment