Advertisement
tod36

SoftUni Final Exam Fundamentals 03 Plant Discovery

Aug 9th, 2020 (edited)
1,579
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. numb_of_lines = int(input())
  2.  
  3. dict_of_plants = {}
  4. for i in range(numb_of_lines):
  5.     commands = input()
  6.     tokens = commands.split("<->")
  7.     dict_of_plants[[tokens[0]][0]] = [tokens[1]]
  8.     dict_of_plants[tokens[0]].append(float(0))
  9. command = input()
  10. while command != "Exhibition":
  11.     token = command.split(": ")
  12.     if token[0] == "Rate":
  13.         token_rate = token[1].split(" - ")
  14.         if token_rate[0] not in dict_of_plants:
  15.             print("error")
  16.         else:
  17.             if dict_of_plants[token_rate[0]][1] == 0:
  18.                 dict_of_plants[token_rate[0]][1] = float(token_rate[1])
  19.             else:
  20.                 k = float((int(dict_of_plants[token_rate[0]][1]) + int(token_rate[1]))/2)
  21.                 dict_of_plants[token_rate[0]][1] = k
  22.     elif token[0] == "Update":
  23.         token_rate = token[1].split(" - ")
  24.         if token_rate[0] not in dict_of_plants:
  25.             print("error")
  26.         else:
  27.             dict_of_plants[token_rate[0]][0] = int(token_rate[1])
  28.     elif token[0] == "Reset":
  29.         if token[1] not in dict_of_plants:
  30.             print("error")
  31.         else:
  32.             dict_of_plants[token[1]][1] = 0
  33.     command = input()
  34. print("Plants for the exhibition:")
  35. for k, v in sorted(dict_of_plants.items(), key=lambda x: (x[0][2], x[0][3]), reverse=True):                 #([x[0][2]], (-[x[0][3]])), reverse=True):
  36.     print(f"- {k}; Rarity: {v[0]}; Rating: {v[1]:.2f}")
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement