Jul-30-2017, 11:11 PM
Hello,
Please help me... How sort correctly the final ranking according the first round and the second round ?
For the ranking final the result must be this:
Drogba 6 points 11 buts
Henry 8 points 14 buts
Owen 10 points 14 buts
In my terminal there is a problem with points ???
I think my function sortFinal() is not correct ? I don't know to do this alone....
Here is my code
Please help me... How sort correctly the final ranking according the first round and the second round ?
For the ranking final the result must be this:
Drogba 6 points 11 buts
Henry 8 points 14 buts
Owen 10 points 14 buts
In my terminal there is a problem with points ???
I think my function sortFinal() is not correct ? I don't know to do this alone....
Here is my code
# --- Step 1/ Print names + points and goals def FirstRound(name, goal, score1): for i in range(len(name)): score1.append(point[i]) print("Name : " + name[i] + " \t " + str(score1[i]) + " points " + str(goal[i]) + " goals ") return score1 def SecondRound(name, goal, score2): for i in range(len(name)): score2.append(point[i]) print("Nom : " + name[i] + " \t " + str(score2[i]) + " points " + str(goal[i]) + " goals ") return score2 # --- Etape 2/ Sort points according goals def Sort(name, goal1, goal2, pts): swap = True while swap: swap = False for i in range(len(name) - 1): if goal1[i + 1] < goal1[i]: name[i], name[i + 1] = name[i + 1], name[i] goal1[i], goal1[i + 1] = goal1[i + 1], goal1[i] goal2[i], goal2[i + 1] = goal2[i + 1], goal2[i] swap = True return name, goal1, goal2, pts # --- Step 3/ Print the number of points def printFinal(name, scoreFinal): for i in range(len(name)): scoreFinal.append(str(score1[i] + score2[i])) print("Nom : " + name[i] + " \t " + (scoreFinal[i]) + " points " ) return scoreFinal print(scoreFinal) # --- Step 4/ Sort according the number of points (from smallest to biggest ) def sortFinal(name, scoreFinal): swap = True while swap: swap = False for i in range(len(name) - 1): if scoreFinal[i + 1] < scoreFinal[i]: name[i], name[i + 1] = name[i + 1], name[i] swap = True return name, scoreFinal name = ["Henry", "Owen", "Drogba"] score1 = [] score2 = [] scoreFinal = [] goal1 = [10,8,6] goal2 = [4,6,5] point = [2,4,6] print(" First round : ") print(" ") name, goal1, goal2, score1 = Sort(name, goal1, goal2, score1) score1 = FirstRound(name, goal1, score1) print("\n ") print(" Second round : ") print(" ") name, goal2, goal1, score2 = Sort(name, goal2, goal1, score2) score2 = SecondRound(name, goal2, score2) print("\n ") print(" Final ranking : ") print(" ") name, scoreFinal = sortFinal(name, scoreFinal) scoreFinal = printFinal(name, scoreFinal)