Advertisement
SimeonTs

SUPyF2 P.-Mid-Exam/2 November 2019/2. - Friends List Mainten

Nov 5th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.12 KB | None | 0 0
  1. """
  2. Programming Fundamentals Mid Exam - 2 November 2019 Group 2
  3. Check your code: https://judge.softuni.bg/Contests/1862/Programming-Fundamentals-Mid-Exam-2-November-2019-Group-2
  4.  
  5. SUPyF2 P.-Mid-Exam/2 November 2019/2. - Friends List Maintenance
  6.  
  7. Problem:
  8. Our player is having trouble with his friend list and some guys are disappearing without a reason so he asks you to
  9. create a program that will figure out what is going on and at the end will bring him a report.
  10. On the first line you will receive all his friends separated by ", ".
  11. On the next lines until the "Report" command you will receive commands. The commands could be:
  12. • Blacklist {name}
  13. • Find the name in the friend list and change it to "Blacklisted" and print on the console:
  14. • "{name} was blacklisted."
  15. • If the name is not in the friend list print:
  16. • "{name} was not found."
  17. • Error {index}
  18. • Check if the username at the given index is not "Blacklisted" or "Lost". If it isn't,
  19. change the username to "Lost" and print on the console:
  20. • "{name} was lost due to an error."
  21. • Change {index} {newName}
  22. • Check if the user at index position is in range of the array. If he is,
  23. change the current username with the new one and print on console:
  24. • "{currentName} changed his username to {newName}."
  25. After you receive "Report" print on the console the count of blacklisted names,
  26. the count of lost names, and the friend list separated by a single space.
  27. Input
  28. • The first input line will contain the usernames that need to be stored.
  29. • On the next input lines until "Report" you will receive commands.
  30. Output
  31. • The output should be in the following format:
  32. • "Blacklisted names: {blacklistedNamesCount}"
  33. • "Lost names: {lostNamesCount}"
  34. • "{name1} {name2} .. {nameN}"
  35. Examples:
  36.  
  37. Input:
  38. Mike, John, Eddie
  39. Blacklist Mike
  40. Error 0
  41. Error 1
  42. Change 2 Mike123
  43. Report
  44.  
  45. Output:
  46. Mike was blacklisted.
  47. John was lost due to an error.
  48. Eddie changed his username to Mike123.
  49. Blacklisted names: 1
  50. Lost names: 1
  51. Blacklisted Lost Mike123
  52.  
  53. Comments:
  54. On the first line are the names from the friendlist that need to be stored in an array.
  55. After that the commands start to flow in. The first command finds Mike and blacklists him: "Mike was blacklisted."
  56. After that "Error 0" failed because the name is already blacklisted and we do nothing.
  57. "Error 1": John is replaced with "Lost" and the messange is sent to the console: "John was lost due to an error."
  58. After that Mike changes his username to Mike123:  "Eddie changed his username to Mike123".
  59. And the report is asked for so the program ends with the shown output.
  60.  
  61. Input:
  62. Mike, John, Eddie, William
  63. Error 3
  64. Error 3
  65. Change 0 Mike123
  66. Blacklist Eddie
  67. Report
  68.  
  69. Output:
  70. William was lost due to an error.
  71. Mike changed his username to Mike123.
  72. Eddie was blacklisted.
  73. Blacklisted names: 1
  74. Lost names: 1
  75. Mike123 John Blacklisted Lost
  76. """
  77. all_friends = input().split(", ")
  78.  
  79. while True:
  80.     command = input().split()
  81.     if command[0] == "Report":
  82.         break
  83.  
  84.     elif command[0] == "Blacklist":
  85.         name = command[1]
  86.         if name not in all_friends:
  87.             print(f"{name} was not found.")
  88.         else:
  89.             index_name = all_friends.index(name)
  90.             all_friends[index_name] = "Blacklisted"
  91.             print(f"{name} was blacklisted.")
  92.  
  93.     elif command[0] == "Error":
  94.         index = int(command[1])
  95.         if 0 <= index < len(all_friends):
  96.             if all_friends[index] != "Blacklisted" and all_friends[index] != "Lost":
  97.                 name = all_friends[index]
  98.                 all_friends[index] = "Lost"
  99.                 print(f"{name} was lost due to an error.")
  100.  
  101.     elif command[0] == "Change":
  102.         index, new_name = int(command[1]), command[2]
  103.         if 0 <= index < len(all_friends):
  104.             current_name = all_friends[index]
  105.             all_friends[index] = new_name
  106.             print(f"{current_name} changed his username to {new_name}.")
  107.  
  108.  
  109. print(f"Blacklisted names: {len([name for name in all_friends if name == 'Blacklisted'])}")
  110. print(f"Lost names: {len([name for name in all_friends if name == 'Lost'])}")
  111. print(*all_friends)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement