dimanche 23 février 2020

How to select 11 best players from a list of players in python?

I am trying to create a program where I should be able to randomly select 11 players from 4 lists of players. Here is what I have tried.

import random
                                                                   # PLayers   Min   Max
                                                                   # ---------------------
wk = ['Rahul', 'Siefiet']                                          # wk         1     4
batsman = ['Rohit', 'Iyer', 'Munro', 'Pandey', 'Guptil', 'Taylor'] # batsman    3     6
bowler = ['Bumrah', 'Southee', 'Chahal', 'Sodhi', 'Dube']          # bowler     3     6
allRounder = ['jadeja', 'Santer', 'Dube']                          # allrounder 1     4
counter = 0

bat = random.randint(3, 6)
allr = random.randint(1, 4)
print(bat)

while counter != 11:
    for a in range(bat):
        print("Batsman:", set(random.choice(batsman)))
        counter += bat #adding random generated number to counter
    for a in range(bat):
        print("Bowler", set(random.choice(bowler)))
        counter += bat
    for a in range(allr):
        print("Allrounder:", set(random.choice(allRounder)))
        counter += allr
    for a in range(allr):
        print("Allrounder:", set(random.choice(wk)))
        counter += allr

When I try to run it. It goes to an infinite loop, Here is a screenshot.

enter image description here

Here is something I want to add to this.

if the randomly generated value for the batsman is 6 then 3 bowlers 1 all-rounder 1 wk
if the randomly generated value for the (batsman is 5) then (3 or 4 bowlers), (1 or 2 all-rounder depending upon if 3 bowlers are opted then 2 all rounders if 4 bowlers are opted then 1 allrounder), (1 or 2 wk depending upon if 2 AR are opted then 1 wk if 1 AR is opted then 2 wk)
And Many more conditions Like This

Any Idea how can I implement it???




Aucun commentaire:

Enregistrer un commentaire