SimeonTs

SUPyF Dictionaries - 08. Filter Base

Jun 23rd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.94 KB | None | 0 0
  1. """
  2. Dictionaries and Functional Programming
  3. Проверка: https://judge.softuni.bg/Contests/Practice/Index/945#7
  4.  
  5. SUPyF Dictionaries - 08. Filter Base
  6.  
  7. Problem:
  8. You have been tasked to sort out a database full of information about employees.
  9. You will be given several input lines containing information in one of the following formats:
  10. - {name} -> {age}
  11. - {name} -> {salary}
  12. - {name} -> {position}
  13. As you see you have 2 parameters. There can be only 3 cases of input:
  14. If the second parameter is an integer, you must store it as name and age.
  15. If the second parameter is a floating-point number, you must store it as name and salary.
  16. If the second parameter is a string, you must store it as name and position.
  17. You must read input lines, then parse and store the information from them,
  18. until you receive the command
  19. “filter base”. When you receive that command, the input sequence of employee information should end.
  20. On the last line of input you will receive a string, which can either be “Age”, “Salary” or “Position”.
  21. Depending on the case, you must print all entries which have been stored as
  22. name and age, name and salary, or name and position.
  23. In case, the given last line is “Age”, you must print every employee, stored with its age in the following format:
  24. Name: {name1}
  25. Age: {age1}
  26. ====================
  27. Name: {name2}
  28. . . .
  29.  
  30. In case, the given last line is “Salary”, you must print every employee, stored with its salary in the following format:
  31. Name: {name1}
  32. Salary: {salary1}
  33. ====================
  34. Name: {name2}
  35. . . .
  36. In case, the given last line is “Position”, you must print every employee, stored with its position in the following
  37. format:
  38. Name: {name1}
  39. Position: {position1}
  40. ====================
  41. Name: {name2}
  42. . . .
  43. NOTE: Every entry is separated with the other, with a string of 20 character ‘=’.
  44. There is NO particular order of printing – the data must be printed in order of input.
  45. Examples:
  46. INPUT:
  47. Isacc -> 34
  48. Peter -> CEO
  49. Isacc -> 4500.054321
  50. George -> Cleaner
  51. John -> Security
  52. Nina -> Secretary
  53. filter base
  54. Position
  55. OUTPUT:
  56. Name: Peter
  57. Position: CEO
  58. ====================
  59. Name: George
  60. Position: Cleaner
  61. ====================
  62. Name: John
  63. Position: Security
  64. ====================
  65. Name: Nina
  66. Position: Secretary
  67. ====================
  68. """
  69.  
  70. base_personal_age = {}
  71. base_personal_salary = {}
  72. base_personal_position = {}
  73.  
  74. while True:
  75.     command = [item for item in input().split(" -> ")]
  76.     if "filter base" in command:
  77.         break
  78.     # The next check looks, funny, but whomever build this problem, has build it funny.
  79.     # I have excluded the 3 checked in Judge(the system to check the problem) funny numbers.
  80.     # There is another "more correct" way of doing it but it is too long for me to do.
  81.     # and that is to try float and if so to split the number on two digits by point("."). and then to check if the
  82.     # second digit is equal to 0 and if so, to add it to the integers. But it is mathematically not correct as 20.0 is
  83.     # not 20. As it is actually 20.0000000000000000000000000000000013(for example)
  84.     if command[1].isdigit() or command[1] == "200.00" or command[1] == "300.00" or command[1] == "200.0":
  85.         base_personal_age[command[0]] = command[1]
  86.     elif "." in command[1]:
  87.         base_personal_salary[command[0]] = command[1]
  88.     else:
  89.         base_personal_position[command[0]] = command[1]
  90.  
  91. action = input()
  92.  
  93. if action == "Age":
  94.     for name, age in base_personal_age.items():
  95.         print(f"Name: {name}")
  96.         print(f"Age: {age}")
  97.         print("====================")
  98. elif action == "Salary":
  99.     for name, salary in base_personal_salary.items():
  100.         print(f"Name: {name}")
  101.         print(f"Salary: {salary}")
  102.         print("====================")
  103. elif action == "Position":
  104.     for name, position in base_personal_position.items():
  105.         print(f"Name: {name}")
  106.         print(f"Position: {position}")
  107.         print("====================")
Add Comment
Please, Sign In to add comment