SimeonTs

SUPyF Exam Preparation 2 - 02 Lists

Aug 16th, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.00 KB | None | 0 0
  1. """
  2. Basics OOP Principles
  3. Check your solution: https://judge.softuni.bg/Contests/Practice/Index/1578#1
  4.  
  5. SUPyF Exam Preparation 2 - 02 Lists
  6. Problem:
  7. Input / Constraints
  8. You will be given a single lines of elements(integers), separated with one or more spaces.
  9. You should check if all elements in the line are unique.
  10. If they are you should increase the value of every even element with the number of 2 and print the list on single row
  11. in ascending order separated by ",".
  12. If they are not unique you should increase every odd element with the number of 3 and print them on single row,
  13. separated with ":"
  14. On the next line you should print sum of the all elements divided by the count of the elements in the list.
  15. You should do that until you receive the command "stop playing"
  16. Output
  17. If the elements are unique
  18. Unique list: {elements in the list, separated by “,”}
  19. Output: {sum of all elements divided by the length of the list}
  20. Else
  21. Non-unique list: {elements in the list, separated by “:”}
  22. Output: {sum of all elements divided by the length of the list}
  23.  
  24. Examples:
  25. ---------
  26. Input:
  27. 1 2  3   4 5 6
  28. 1 1 2   2 1 4 7 7 8 8
  29. 5 5 5 5
  30. stop playing
  31.  
  32. Output:
  33. Unique list: 1,3,4,5,6,8
  34. Output: 4.50
  35. Non-unique list: 2:2:4:4:4:4:8:8:10:10
  36. Output: 5.60
  37. Non-unique list: 8:8:8:8
  38. Output: 8.00
  39.  
  40. Input:
  41. 1      1 1
  42. stop playing
  43.  
  44. Output:
  45. Non-unique list: 4:4:4
  46. Output: 4.00
  47. """
  48.  
  49. while True:
  50.     command = input()
  51.     if command == "stop playing":
  52.         break
  53.     nums = [int(item) for item in command.split()]
  54.     if_unique = len(set(nums)) == len(nums)
  55.     if if_unique:
  56.         nums = sorted([item + 2 if item % 2 == 0 else item for item in nums])
  57.         print(f"Unique list: {','.join([str(item) for item in nums])}")
  58.         print(f"Output: {(sum(nums) / len(nums)):.2f}")
  59.     else:
  60.         nums = sorted([item + 3 if item % 2 != 0 else item for item in nums])
  61.         print(f"Non-unique list: {':'.join([str(item) for item in nums])}")
  62.         print(f"Output: {(sum(nums) / len(nums)):.2f}")
Add Comment
Please, Sign In to add comment