Advertisement
GeorgiLukanov87

Python-Advanced-Exercises , Tuples and Sets - Lab

Aug 18th, 2022
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.57 KB | None | 0 0
  1. # Python-Advanced-Exercises , Tuples and Sets - Lab
  2. # https://judge.softuni.org/Contests/Practice/Index/1833#4
  3.  
  4. # 01. Count Same Values
  5. # 02. Students' Grades
  6. # 03. Record Unique Names
  7. # 04. Parking Lot
  8. # 05. SoftUni Party
  9. # 06. Summation Pairs
  10. ========================================================================================================
  11. # 01. Count Same Values
  12.  
  13. data = (float(x) for x in input().split(' '))
  14. nums_dict = {}
  15. for num in data:
  16.     if num not in nums_dict:
  17.         nums_dict[num] = 0
  18.     nums_dict[num] += 1
  19.  
  20. for kvp in nums_dict.items():
  21.     print(f'{kvp[0]} - {kvp[1]} times')
  22.  
  23.    
  24. ========================================================================================================
  25. # 02. Students' Grades
  26.  
  27. n = int(input())
  28. students = {}
  29.  
  30. for _ in range(n):
  31.     current_student = input().split(" ")
  32.     name = current_student[0]
  33.     grade = float(current_student[1])
  34.     if name not in students:
  35.         students[name] = []
  36.     students[name].append(grade)
  37.  
  38. for student in students.items():
  39.     to_print = ' '.join(f"{x:.2f}" for x in student[1])
  40.     average_grade = sum(student[1]) / len(student[1])
  41.     print(f'{student[0]} -> {to_print} (avg: {average_grade:.2f})')
  42.  
  43.    
  44. ========================================================================================================
  45. # 03. Record Unique Names
  46.  
  47. n = int(input())
  48.  
  49. names_set_list = set()
  50. for _ in range(n):
  51.     name = input()
  52.     names_set_list.add(name)
  53.  
  54. print(*names_set_list, sep='\n')
  55.  
  56.  
  57. ========================================================================================================
  58. # 04. Parking Lot
  59.  
  60. n = int(input())
  61. parking_lot = set()
  62. for _ in range(n):
  63.     details = input().split(', ')
  64.     direction = details[0]
  65.     car_number = details[1]
  66.     if direction == 'IN':
  67.         parking_lot.add(car_number)
  68.     else:
  69.         parking_lot.remove(car_number)
  70.  
  71. if parking_lot:
  72.     for car_num in parking_lot:
  73.         print(car_num)
  74. else:
  75.     print('Parking Lot is Empty')
  76.  
  77.    
  78. ========================================================================================================
  79. # 05. SoftUni Party
  80.  
  81. n = int(input())
  82. regular_guests = set()
  83. vip_guests = set()
  84.  
  85. for _ in range(n):
  86.     reg_code = input()
  87.     if reg_code[0].isdigit():
  88.         vip_guests.add(reg_code)
  89.     else:
  90.         regular_guests.add(reg_code)
  91.  
  92. guest_arrived = input()
  93.  
  94. while not guest_arrived == 'END':
  95.     current_guest = guest_arrived
  96.     if current_guest[0].isdigit():
  97.         if current_guest in vip_guests:
  98.             vip_guests.remove(current_guest)
  99.  
  100.     elif current_guest in regular_guests:
  101.         regular_guests.remove(current_guest)
  102.  
  103.     guest_arrived = input()
  104.  
  105. print(len(vip_guests)+len(regular_guests))
  106.  
  107. for name in sorted(vip_guests):
  108.     print(name)
  109.  
  110. for name in sorted(regular_guests):
  111.     print(name)
  112.  
  113.  
  114. ========================================================================================================
  115. # 06. Summation Pairs
  116.  
  117. from collections import deque
  118.  
  119. numbers = deque([int(x) for x in input().split()])
  120. target_sum = int(input())
  121.  
  122. unique_pairs = set()
  123. iterations = 0
  124.  
  125. while numbers:
  126.     first_num = numbers.popleft()
  127.     for num in numbers:
  128.         iterations += 1
  129.         if (num + first_num) == target_sum:
  130.             unique_pairs.add((first_num, num))
  131.             print(f'{first_num} + {num} = {target_sum}')
  132.  
  133. print(f'Iterations done: {iterations}')
  134. for pair in unique_pairs:
  135.     print(pair)
  136.  
  137.    
  138. ========================================================================================================
  139.  
  140.  
  141.  
  142.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement