hi im creating a tiny lotto program and the program needs to sort out the first 6 numbers of the dictionary using insertion sort and the last 2 using selection sort i have done the code and complied it but it give me the below set of result, the last list keeps repeating instead of it sorting it out and printing it can i know why and how to fix it
Player 1 has numbers [17, 21, 0, 3, 25, 22, 4, 10]
Player 2 has numbers [13, 22, 11, 20, 24, 28, 20, 7]
Player 3 has numbers [8, 11, 16, 22, 14, 9, 11, 1]
Player 4 has numbers [8, 23, 28, 30, 6, 19, 12, 24]
Player 5 has numbers [22, 10, 2, 13, 4, 7, 15, 27]
Player 6 has numbers [5, 20, 10, 11, 5, 2, 27, 13]
Player 7 has numbers [25, 9, 22, 5, 14, 8, 25, 20]
Player 8 has numbers [16, 19, 25, 6, 17, 18, 13, 13]
Player 9 has numbers [8, 18, 16, 8, 1, 14, 4, 8]
Sorted array is:
[8, 18, 16, 8, 1, 14, 4, 8]
[8, 18, 16, 8, 1, 14, 4, 8]
[8, 18, 16, 8, 1, 14, 4, 8]
[8, 18, 16, 8, 1, 14, 4, 8]
[8, 18, 16, 8, 1, 14, 4, 8]
[8, 18, 16, 8, 1, 14, 4, 8]
[8, 18, 16, 8, 1, 14, 4, 8]
[8, 18, 16, 8, 1, 14, 4, 8]
the 8 winning numbers are
[9, 12, 5, 17, 14, 17] [16, 4]
import random
def random_generator():
randomNumber = random.randint(0,30)
return randomNumber
def winningNumbers():
winningPwn = []
winningSwn = []
for currentPwn in range(6):
randomPWN = random_generator()
winningPwn.append(randomPWN)
for currentSwn in range(2):
randomSwn = random_generator()
winningSwn.append(randomSwn)
return winningPwn, winningSwn
def printWinningNumber(lotteryNumbers):
for currentLotteryIndex in range(len(lotteryNumbers)):
print(lotteryNumbers[currentLotteryIndex],end = " ")
def draw():
winning = winningNumbers()
print("the 8 winning numbers are")
printWinningNumber(winning)
def generatePlayers():
players = {}
for player_id in range(1, 10):
player_list = []
for i in range(8):
player_list.append(random_generator())
players[player_id] = player_list
for player_id in players:
print("Player {} has numbers {}".format(player_id, players[player_id]))
insertionsort(players[player_id])
print ("Sorted array is:")
for i in players[player_id]:
print (players[player_id])
return players
def insertionsort(players):
for i in range(1, len(players)):
value = players[i]
while i >0 :
if value < players[i]:
players[i+1] = players[i]
players[i] = value
i = i - 1
else:
break
generatePlayers()
draw()