Advertisement
GeorgiLukanov87

Python Advanced Exam - 22 October 2022

Oct 22nd, 2022 (edited)
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.86 KB | None | 0 0
  1. # Python Advanced Exam - 22 October 2022
  2.  
  3. ============================================================================================================
  4.  
  5. # 01. Energy Drinks
  6.  
  7. from collections import deque
  8.  
  9. caffeine = deque([int(x) for x in input().split(', ')])
  10. drinks = deque([int(x) for x in input().split(', ')])
  11.  
  12. initial_caffeine = 0
  13. while caffeine and drinks:
  14.     last_caffeine = caffeine[-1]
  15.     first_drink = drinks[0]
  16.  
  17.     result = last_caffeine * first_drink
  18.     if result + initial_caffeine <= 300:
  19.         initial_caffeine += result
  20.     else:
  21.         drinks.append(first_drink)
  22.         initial_caffeine -= 30
  23.         if initial_caffeine <= 0:
  24.             initial_caffeine = 0
  25.  
  26.     caffeine.pop()
  27.     drinks.popleft()
  28.  
  29. if drinks:
  30.     print(f'Drinks left: {", ".join(str(x) for x in drinks)}')
  31. else:
  32.     print("At least Stamat wasn't exceeding the maximum caffeine.")
  33. print(f'Stamat is going to sleep with {initial_caffeine} mg caffeine.')
  34.  
  35. ============================================================================================================
  36. # 02. Rally Racing
  37.  
  38. def get_next_position(direction, row, col):
  39.     if direction == 'left':
  40.         return (row, col - 1)
  41.     elif direction == 'right':
  42.         return (row, col + 1)
  43.     elif direction == 'up':
  44.         return (row - 1, col)
  45.     elif direction == 'down':
  46.         return (row + 1, col)
  47.  
  48.  
  49. SIZE = int(input())
  50. racing_number = input()
  51. row, col, matrix, tunnel = 0, 0, [], []
  52.  
  53. for row_index in range(SIZE):
  54.     matrix.append(input().split())
  55.     for col_index in range(SIZE):
  56.         if matrix[row_index][col_index] == 'T':
  57.             tunnel.append((row_index, col_index))
  58.  
  59. clear_tunel = tunnel.copy()
  60. total_km = 0
  61. while True:
  62.     command = input()
  63.     if command == "End":
  64.         print(f"Racing car {racing_number} DNF.")
  65.         break
  66.     row, col = get_next_position(command, row, col)
  67.     current_step = matrix[row][col]
  68.     total_km += 10
  69.  
  70.     if current_step == 'T':
  71.         tunnel.remove((row, col))
  72.         row, col = tunnel[0][0], tunnel[0][1]
  73.         total_km += 20
  74.         for el in clear_tunel:
  75.             matrix[el[0]][el[1]] = '.'
  76.  
  77.     elif current_step == 'F':
  78.         print(f'Racing car {racing_number} finished the stage!')
  79.         break
  80.  
  81. matrix[row][col] = 'C'
  82. print(f'Distance covered {total_km} km.')
  83. for el in matrix:
  84.     print(*el, sep='')
  85.  
  86.  
  87. ============================================================================================================
  88.  
  89. # 03. Hourly Forecast
  90.  
  91. def forecast(*args):
  92.     my_dict = {"Sunny": [], "Cloudy": [], "Rainy": []}
  93.     for el in args:
  94.         town = el[0]
  95.         weather = el[1]
  96.         my_dict[weather].append(town)
  97.  
  98.     result = ""
  99.     for weather, town in my_dict.items():
  100.         for sub_town in sorted(town):
  101.             result += f'{sub_town} - {weather}\n'
  102.  
  103.     return result.strip()
  104.  
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement