Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Python Advanced Exam - 22 October 2022
- ============================================================================================================
- # 01. Energy Drinks
- from collections import deque
- caffeine = deque([int(x) for x in input().split(', ')])
- drinks = deque([int(x) for x in input().split(', ')])
- initial_caffeine = 0
- while caffeine and drinks:
- last_caffeine = caffeine[-1]
- first_drink = drinks[0]
- result = last_caffeine * first_drink
- if result + initial_caffeine <= 300:
- initial_caffeine += result
- else:
- drinks.append(first_drink)
- initial_caffeine -= 30
- if initial_caffeine <= 0:
- initial_caffeine = 0
- caffeine.pop()
- drinks.popleft()
- if drinks:
- print(f'Drinks left: {", ".join(str(x) for x in drinks)}')
- else:
- print("At least Stamat wasn't exceeding the maximum caffeine.")
- print(f'Stamat is going to sleep with {initial_caffeine} mg caffeine.')
- ============================================================================================================
- # 02. Rally Racing
- def get_next_position(direction, row, col):
- if direction == 'left':
- return (row, col - 1)
- elif direction == 'right':
- return (row, col + 1)
- elif direction == 'up':
- return (row - 1, col)
- elif direction == 'down':
- return (row + 1, col)
- SIZE = int(input())
- racing_number = input()
- row, col, matrix, tunnel = 0, 0, [], []
- for row_index in range(SIZE):
- matrix.append(input().split())
- for col_index in range(SIZE):
- if matrix[row_index][col_index] == 'T':
- tunnel.append((row_index, col_index))
- clear_tunel = tunnel.copy()
- total_km = 0
- while True:
- command = input()
- if command == "End":
- print(f"Racing car {racing_number} DNF.")
- break
- row, col = get_next_position(command, row, col)
- current_step = matrix[row][col]
- total_km += 10
- if current_step == 'T':
- tunnel.remove((row, col))
- row, col = tunnel[0][0], tunnel[0][1]
- total_km += 20
- for el in clear_tunel:
- matrix[el[0]][el[1]] = '.'
- elif current_step == 'F':
- print(f'Racing car {racing_number} finished the stage!')
- break
- matrix[row][col] = 'C'
- print(f'Distance covered {total_km} km.')
- for el in matrix:
- print(*el, sep='')
- ============================================================================================================
- # 03. Hourly Forecast
- def forecast(*args):
- my_dict = {"Sunny": [], "Cloudy": [], "Rainy": []}
- for el in args:
- town = el[0]
- weather = el[1]
- my_dict[weather].append(town)
- result = ""
- for weather, town in my_dict.items():
- for sub_town in sorted(town):
- result += f'{sub_town} - {weather}\n'
- return result.strip()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement