Advertisement
go6odn28

3_plant_dicovery

Mar 30th, 2024
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.63 KB | None | 0 0
  1. rows = int(input())
  2. plants_data = {}
  3. RARITY = "rarity"
  4. RATINGS = "ratings"
  5.  
  6. for _ in range(rows):
  7.     info = input().split("<->")
  8.     curr_plant, rarity = info[0], int(info[1])
  9.     if curr_plant not in plants_data:
  10.         plants_data[curr_plant] = {}
  11.         plants_data[curr_plant][RARITY] = 0
  12.         plants_data[curr_plant][RATINGS] = []
  13.     plants_data[curr_plant][RARITY] += rarity
  14.  
  15. while True:
  16.     command = input()
  17.     if command == "Exhibition":
  18.         break
  19.  
  20.     data = command.replace(":", " -")
  21.     data = data.split(" - ")
  22.     command = data[0]
  23.     plant = data[1]
  24.  
  25.     if plant not in plants_data:
  26.         print("error")
  27.         continue
  28.  
  29.     elif command == "Rate":
  30.         rating = int(data[2])
  31.         plants_data[plant][RATINGS].append(rating)
  32.  
  33.     elif command == "Update":
  34.         new_rarity = int(data[2])
  35.         plants_data[plant][RARITY] = new_rarity
  36.  
  37.     elif command == "Reset":
  38.         plants_data[plant][RATINGS].clear()
  39.  
  40. print("Plants for the exhibition:")
  41. for plant_name, pl_data in plants_data.items():
  42.     current_rarity = pl_data[RARITY]
  43.     average_rating = sum(pl_data[RATINGS]) / len(pl_data[RATINGS]) if pl_data[RATINGS] else 0
  44.     print(f"- {plant_name}; Rarity: {current_rarity}; Rating: {average_rating:.2f}")
  45.  
  46.  
  47.  
  48. ###################################################################
  49. # def take_plants_data(plants_data_, rows_):
  50. #     for _ in range(rows_):
  51. #         plant_, rariry = input().split("<->")
  52. #         plants_data_[plant_] = {"rarity": rariry, "ratings": []}
  53. #     return plants_data_
  54. #
  55. #
  56. # def rate(plants_data_, plant_, rating_):
  57. #     if plant_ not in plants_data_:
  58. #         print("error")
  59. #     else:
  60. #         plants_data_[plant_]["ratings"].append(rating_)
  61. #     return plants_data_
  62. #
  63. #
  64. # def update_plants_data(plants_data_, plant_, new_rarity_):
  65. #     if plant_ not in plants_data_:
  66. #         print("error")
  67. #     else:
  68. #         plants_data_[plant_]["rarity"] = new_rarity_
  69. #     return plants_data_
  70. #
  71. #
  72. # def reset(plants_data_, plant_):
  73. #     if plant_ not in plants_data_:
  74. #         print("error")
  75. #     else:
  76. #         plants_data_[plant_]["ratings"].clear()
  77. #     return plants_data_
  78. #
  79. #
  80. # def print_result(plants_data_):
  81. #     result = ''
  82. #     result += "Plants for the exhibition:\n"
  83. #
  84. #     for curr_plant, plant_information in plants_data_.items():
  85. #         rarity = plant_information["rarity"]
  86. #         ratings = plant_information["ratings"]
  87. #         if ratings:
  88. #             average_rating = sum(ratings) / len(ratings)
  89. #         else:
  90. #             average_rating = 0
  91. #         result += f"- {curr_plant}; Rarity: {rarity}; Rating: {average_rating:.2f}\n"
  92. #     return print(result)
  93. #
  94. #
  95. # def main():
  96. #     plants_data = {}
  97. #     rows = int(input())
  98. #
  99. #     plants_data = take_plants_data(plants_data, rows)
  100. #
  101. #     while True:
  102. #         data = input().split(": ")
  103. #         command = data[0]
  104. #
  105. #         if command == "Exhibition":
  106. #             break
  107. #
  108. #         elif command == "Rate":
  109. #             plant_info = data[1].split(" - ")
  110. #             plant, rating = plant_info[0], int(plant_info[1])
  111. #             plants_data = rate(plants_data, plant, rating)
  112. #
  113. #         elif command == "Update":
  114. #             plant_info = data[1].split(" - ")
  115. #             plant, new_rarity = plant_info[0], int(plant_info[1])
  116. #             plants_data = update_plants_data(plants_data, plant, new_rarity)
  117. #
  118. #         elif command == "Reset":
  119. #             plant = data[1]
  120. #             plants_data = reset(plants_data, plant)
  121. #
  122. #     print_result(plants_data)
  123. #
  124. #
  125. # if __name__ == "__main__":
  126. #     main()
  127.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement