Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
################### FONCTIONS
############## CRÉER UN RÉSEAU
def results_hash ( votes ):
"" " Compter les votes par candidat et par mention
Renvoie une dictée de noms de candidats contenant des tableaux de votes.
"" "
candidats_results = {
candidat: [ 0 ] * len ( MENTIONS )
pour candidat en CANDIDATS .keys ()
}
pour vote en votes:
pour le candidat, mentionner dans vote.items ():
candidats_résultats [candidat] [mention] + = 1
retour candidats_résultats
############## CALCULER MEDIAN
def majoritary_mentions_hash ( candidats_résultats ):
r = {}
pour candidat, candidate_result dans candidats_results.items ():
cumulated_votes = 0
pour mention, vote_count en énumérer (candidate_result):
cumulated_votes + = vote_count
si MEDIAN < cumulated_votes :
r [candidat] = {
" mention " : mention,
" score " : cumulated_votes
}
Pause
retour r
############## TRIER LES CANDIDATS
def sort_candidates_by ( mentionne ):
# # tri des bulles c'est parti!
unsorted = [(key, (mention [ " mention " ], mention [ " score " ])) pour key, mention dans mentions.items ()]
swapped = True
pendant l' échange:
swapped = False
pour j dans la plage ( 0 , len (non trié) - 1 ):
# # mais nous avons besoin d'un tri à bulle INVERSE ;-)
# (notez qu'ici nous comparons les tuples, ce qui est plutôt soigné)
si non trié [j + 1 ] [ 1 ] > non trié [j] [ 1 ]:
non trié [j + 1 ], non trié [j] = non trié [j], non trié [j + 1 ]
swapped = True
############## FORMAT RÉSULTATS
def print_results ( résultats ):
pour i, résultat en énumérer (résultats):
nom = CANDIDATS [résultat [ " nom " ]]
mention = MENTIONS [résultat [ " mention " ]]
score = résultat [ " score " ] * 100 . / VOTES
si i == 0 :
print ( " Gagnant: {} avec { : .2f } % d e mentionne {} ou réduit " .format (
nom, score, mention
))
continuer
sinon :
print ( " - {} avec { : .2f } % d e mentionne {} ou malgré " .format (
nom, score, mention
))
Votre code va ici
@@ -128,10 +57,6 @@ def print_results (résultats):
def main ():
votes = create_votes ()
results = results_hash (votes)
majoritary_mentions = majoritary_mentions_hash (résultats)
sorted_candidates = sort_candidates_by (majoritary_mentions)
print_results (sorted_candidates)
si name == ' main ' :
principale()