SimeonTs

SUPyF2 Dict-Exercise - 05. SoftUni Parking

Oct 24th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.60 KB | None | 0 0
  1. """
  2. Dictionaries - Exercise
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1737#4
  4.  
  5. SUPyF2 Dict-Exercise - 05. SoftUni Parking
  6.  
  7. Problem:
  8. SoftUni just got a new parking lot. It's so fancy, it even has online parking validation.
  9. Except the online service doesn't work. It can only receive users' data,
  10. but it doesn't know what to do with it. Good thing you're on the dev team and know how to fix it, right?
  11. Write a program, which validates a parking place for an online service.
  12. Users can register to park and unregister to leave.
  13. The program receives 2 types of commands:
  14. • "register {username} {licensePlateNumber}":
  15. o   The system only supports one car per user at the moment,
  16. so if a user tries to register another license plate, using the same username, the system should print:
  17. "ERROR: already registered with plate number {licensePlateNumber}"
  18. o   If the aforementioned checks passes successfully, the plate can be registered, so the system should print:
  19. "{username} registered {licensePlateNumber} successfully"
  20. • "unregister {username}":
  21. o   If the user is not present in the database, the system should print:
  22. "ERROR: user {username} not found"
  23. o   If the aforementioned check passes successfully, the system should print:
  24. "{username} unregistered successfully"
  25. After you execute all of the commands, print all the currently registered users and their license plates in the format:
  26. • "{username} => {licensePlateNumber}"
  27. Input
  28. • First line: n – number of commands – integer
  29. • Next n lines: commands in one of the two possible formats:
  30. o   Register: "register {username} {licensePlateNumber}"
  31. o   Unregister: "unregister {username}"
  32. The input will always be valid and you do not need to check it explicitly.
  33.  
  34. Examples:
  35. Input:
  36. 5
  37. register John CS1234JS
  38. register George JAVA123S
  39. register Andy AB4142CD
  40. register Jesica VR1223EE
  41. unregister Andy
  42.  
  43. Output:
  44. John registered CS1234JS successfully
  45. George registered JAVA123S successfully
  46. Andy registered AB4142CD successfully
  47. Jesica registered VR1223EE successfully
  48. Andy unregistered successfully
  49. John => CS1234JS
  50. George => JAVA123S
  51. Jesica => VR1223EE
  52.  
  53. Input:
  54. 4
  55. register Jony AA4132BB
  56. register Jony AA4132BB
  57. register Linda AA9999BB
  58. unregister Jony
  59.  
  60. Output:
  61. Jony registered AA4132BB successfully
  62. ERROR: already registered with plate number AA4132BB
  63. Linda registered AA9999BB successfully
  64. Jony unregistered successfully
  65. Linda => AA9999BB
  66.  
  67. Input:
  68. 6
  69. register Jacob MM1111XX
  70. register Anthony AB1111XX
  71. unregister Jacob
  72. register Joshua DD1111XX
  73. unregister Lily
  74. register Samantha AA9999BB
  75.  
  76. Output:
  77. Jacob registered MM1111XX successfully
  78. Anthony registered AB1111XX successfully
  79. Jacob unregistered successfully
  80. Joshua registered DD1111XX successfully
  81. ERROR: user Lily not found
  82. Samantha registered AA9999BB successfully
  83. Joshua => DD1111XX
  84. Anthony => AB1111XX
  85. Samantha => AA9999BB
  86. """
  87. car_park = {}
  88.  
  89. for time in range(int(input())):
  90.     command = input().split()
  91.     username = command[1]
  92.     if command[0] == "register":
  93.         reg_number = command[2]
  94.         if username in car_park:
  95.             print(f"ERROR: already registered with plate number {car_park[username]}")
  96.         else:
  97.             car_park[username] = reg_number
  98.             print(f"{username} registered {reg_number} successfully")
  99.     elif command[0] == "unregister":
  100.         if username not in car_park:
  101.             print(f"ERROR: user {username} not found")
  102.         else:
  103.             car_park.pop(username)
  104.             print(f"{username} unregistered successfully")
  105.  
  106. for username, reg_number in car_park.items():
  107.     print(f"{username} => {reg_number}")
Advertisement
Add Comment
Please, Sign In to add comment