Advertisement
KNenov96

03.plant discovery

Nov 11th, 2022 (edited)
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.21 KB | None | 0 0
  1. ### работещ код 100/100
  2.  
  3. number_of_information = int(input())
  4. my_plants = {}
  5.  
  6. for receiving in range(number_of_information):
  7.     information_for_plants = input().split("<->")
  8.     plant_name = information_for_plants[0]
  9.     rarity = information_for_plants[1]
  10.     my_plants[plant_name] = [rarity, []]
  11.  
  12. exhibition = False
  13. while not exhibition:
  14.     commands = input()
  15.     if commands == "Exhibition":
  16.         exhibition = True
  17.         break
  18.  
  19.     commands = commands.split(": ")
  20.     current_command = commands[0]
  21.     if current_command == "Rate":
  22.         plant_for_rate = commands[1].split(" - ")[0]
  23.         rating = int(commands[1].split(" - ")[1])
  24.         if plant_for_rate in my_plants:
  25.             my_plants[plant_for_rate][1].append(rating)
  26.         else:
  27.             print("error")
  28.  
  29.     elif current_command == "Update":
  30.         plant_for_update = commands[1].split(" - ")[0]
  31.         plant_rarity = commands[1].split(" - ")[1]
  32.         if plant_for_update in my_plants:
  33.             my_plants[plant_for_update][0] = plant_rarity
  34.         else:
  35.             print("error")
  36.  
  37.     elif current_command == "Reset":
  38.         plant_for_reset = commands[1]
  39.         if plant_for_reset in my_plants:
  40.             my_plants[plant_for_reset][1] = []
  41.         else:
  42.             print("error")
  43.  
  44. print("Plants for the exhibition:")
  45. for plant in my_plants:
  46.     if len(my_plants[plant][1]) > 0:
  47.         rating_current_plant = sum(my_plants[plant][1]) / len(my_plants[plant][1])
  48.     else:
  49.         rating_current_plant = 0
  50.     print(f"- {plant}; Rarity: {my_plants[plant][0]}; Rating: {rating_current_plant:.2f}")
  51.  
  52. ##### не работещ код 87/100 рънтайм
  53.  
  54. def main():
  55.     discovered_plants = {}
  56.     number_of_information = int(input())
  57.     for receiving_info in range(number_of_information):
  58.         plant, rarity = input().split("<->")
  59.         discovered_plants[plant] = [rarity]
  60.  
  61.     commands = input()
  62.     while commands != "Exhibition":
  63.         current_command = commands.split(": ")[0]
  64.         name_plant = commands.split(": ")[1].split(" - ")[0]
  65.  
  66.         if name_plant not in discovered_plants:
  67.             print("error")
  68.         elif current_command == "Rate":
  69.             rate_plant = int(commands.split(": ")[1].split(" - ")[1])
  70.             discovered_plants[name_plant].append(rate_plant)
  71.         elif current_command == "Update":
  72.             rarity_plant = commands.split(": ")[1].split(" - ")[1]
  73.             discovered_plants[name_plant][0] = rarity_plant
  74.         elif current_command == "Reset":
  75.             discovered_plants[name_plant] = discovered_plants[name_plant][0]
  76.            
  77.         commands = input()
  78.  
  79.     print("Plants for the exhibition:")
  80.     for plants_for_exhibition in discovered_plants:
  81.         name_of_plant = plants_for_exhibition
  82.         rarity_of_plant = discovered_plants[plants_for_exhibition][0]
  83.         calculating_rating = 0
  84.         if len(discovered_plants[plants_for_exhibition]) > 1:
  85.             calculating_rating = sum(discovered_plants[plants_for_exhibition][1:]) / \
  86.                                  len(discovered_plants[plants_for_exhibition][1:])
  87.  
  88.         print(f"- {name_of_plant}; Rarity: {rarity_of_plant}; Rating: {calculating_rating:.2f}")
  89.  
  90. main()
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement