Python random horserace -


i'm trying create function takes in list give of predicted out come of race , bet. example, predict outcome [1,3,4,2] horse 1 in 1st, horse 3, in 2nd etc... prediction compared randomized/ shuffled list a. have set couple of if statements try , compare both items in each list each other ends giving me placements correct if not. stuck!!!

def horserace(glist,bet):      import random      = [1,2,3,4]     random.shuffle(a,random.random)     = 0     x = 0     while < 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         = + 1     print(x)     print(a)     print(glist)     if x == 4:         money = bet*2         print("you guessed 4 position(s) correctly , won $ %d !"%money)     if x == 0:         money = 0.00         print("you guessed no position(s) correctly , won $ %d !"%money)     if x == 1:         money = bet         print("you guessed 1 position(s) correctly , won $ %d !"%money)      if x == 2:         money = bet         print("you guessed 2 position(s) correctly , won $ %d !"%money)      if x == 3:         money = bet         print("you guessed 3 position(s) correctly , won $ %d !"%money) 

your while loop should more this

  while < len(glist):         if glist[i] == a[i]:             x = x + 1         else:             x = x         = + 1 

that way, you're comparing value in cell position i in glist value in same cell position in a. right now, code says add 1 x long value glist[i] equal of:

a[1], a[2], a[3], a[4]

which of course wil be


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

IIS->Tomcat Redirect: multiple worker with default -