Advertisement
GeorgiLukanov87

03. Football League_еxam_prep

Jun 24th, 2022
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.56 KB | None | 0 0
  1. def clean_string(some_str: str, some_key: str):
  2.     start_index = some_str.index(some_key[0].upper())
  3.     word = some_str[start_index + len(some_key):]
  4.     word = word[::-1]
  5.     new_index = word[::-1].index(f"{key[0]}")
  6.     new_word = word[::-1][:new_index]
  7.     result = new_word.upper()[::-1]
  8.     return result
  9.  
  10.  
  11. def who_won(result1, result2):
  12.     team_1 = False
  13.     team_2 = False
  14.     draw = False
  15.     if result1 > result2:
  16.         team_1 = True
  17.     elif result1 < result2:
  18.         team_2 = True
  19.     else:
  20.         draw = True
  21.     current_status = [team_1, team_2, draw]
  22.     return current_status
  23.  
  24.  
  25. def making_teams_inside_dict(team_one, team_two, some_dict):
  26.     if team_one not in all_teams_scores:
  27.         all_teams_scores[team_one] = 0
  28.     else:
  29.         all_teams_scores[team_one] += 0
  30.  
  31.     if team_two not in all_teams_scores:
  32.         all_teams_scores[team_two] = 0
  33.     else:
  34.         all_teams_scores[team_two] += 0
  35.     return some_dict
  36.  
  37.  
  38. def if_result_match(some_dict):
  39.     results = []
  40.     zero_result_counter = 0
  41.     for key, value in some_dict.items():
  42.         if value > 0:
  43.             results.append(value)
  44.         else:
  45.             zero_result_counter += 1
  46.  
  47.     if (len(some_dict) - zero_result_counter) != len(set(some_dict)):
  48.         return True
  49.     return False
  50.  
  51.  
  52. key = input()
  53. data = input()
  54. score = []
  55. all_teams_scores = {}
  56. all_teams_goals = {}
  57. while not data == 'final':
  58.     data = data.split(' ')
  59.     score = data[-1]
  60.     goals1 = int(score[0])
  61.     goals2 = int(score[-1])
  62.     status = who_won(goals1, goals2)
  63.     team1 = data[0]
  64.     team1 = clean_string(team1, key)
  65.     team2 = data[1]
  66.     team2 = clean_string(team2, key)
  67.     # /////////////////////////////////////////////////////////////////////////////////////////////////
  68.     if team1 not in all_teams_goals:
  69.         all_teams_goals[team1] = goals1
  70.     else:
  71.         all_teams_goals[team1] += goals1
  72.  
  73.     if team2 not in all_teams_goals:
  74.         all_teams_goals[team2] = goals2
  75.     else:
  76.         all_teams_goals[team2] += goals2
  77.     # ////////////////////////////////////////////////////////////////////////////////////////////////////
  78.     all_teams_scores = making_teams_inside_dict(team1, team2, all_teams_scores)
  79.     if team1 in all_teams_scores:
  80.         if status[0]:
  81.             all_teams_scores[team1] += 3
  82.         elif not status[0] and not status[2]:
  83.             all_teams_scores[team1] += 0
  84.         else:
  85.             all_teams_scores[team1] += 1
  86.     if team2 in all_teams_scores:
  87.         if status[1]:
  88.             all_teams_scores[team2] += 3
  89.         elif not status[1] and not status[2]:
  90.             all_teams_scores[team2] += 0
  91.         else:
  92.             all_teams_scores[team2] += 1
  93.     # ////////////////////////////////////////////////////////////////////////////////////////////////////
  94.     data = input()
  95.  
  96. print('League standings:')
  97. is_matched1 = (if_result_match(all_teams_scores))
  98. is_matched2 = (if_result_match(all_teams_goals))
  99.  
  100. if is_matched1 or is_matched2:
  101.     sorted_score = sorted(all_teams_scores.items(), key=lambda x: x[0])
  102.     sorted_goals = sorted(all_teams_goals.items(), key=lambda x: x[0])
  103.  
  104. sorted_score = sorted(all_teams_scores.items(), key=lambda x: x[1], reverse=True)
  105. sorted_goals = sorted(all_teams_goals.items(), key=lambda x: x[1], reverse=True)
  106.  
  107. position = 0
  108. for team in sorted_score:
  109.     position += 1
  110.     print(f"{position}. {team[0]} {team[1]}")
  111.  
  112. print('Top 3 scored goals:')
  113. counter = 0
  114. for team in sorted_goals:
  115.     counter += 1
  116.     print(f"- {team[0]} -> {team[1]}")
  117.     if counter == 3:
  118.         break
  119.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement