Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Python Advanced Exam - 27 June 2020
- #
- # https://judge.softuni.org/Contests/Practice/Index/2456#0
- # 01. Bombs
- # 02. Snake
- # 03. List Manipulator
- -----------------------------------------------------------------------------------------------
- # 01. Bombs
- from collections import deque
- effects = deque([int(x) for x in input().split(', ')])
- casings = deque([int(x) for x in input().split(', ')])
- valid_crafting_result = {40: 'Datura Bombs', 60: 'Cherry Bombs', 120: 'Smoke Decoy Bombs'}
- crafted_bombs = {'Cherry Bombs': 0, "Datura Bombs": 0, 'Smoke Decoy Bombs': 0}
- target_reached = False
- while True:
- if not effects or not casings:
- break
- element1 = effects[0]
- element2 = casings[-1]
- result = element1 + element2
- if result in valid_crafting_result.keys():
- crafted_bombs[valid_crafting_result[result]] += 1
- effects.popleft()
- casings.pop()
- else:
- casings[-1] -= 5
- if crafted_bombs['Cherry Bombs'] > 2 and \
- crafted_bombs["Datura Bombs"] > 2 and \
- crafted_bombs['Smoke Decoy Bombs'] > 2:
- target_reached = True
- break
- if target_reached:
- print(f'Bene! You have successfully filled the bomb pouch!')
- else:
- print(f"You don't have enough materials to fill the bomb pouch.")
- if effects:
- print(f'Bomb Effects: {", ".join([str(el) for el in effects])}')
- else:
- print('Bomb Effects: empty')
- if casings:
- print(f"Bomb Casings: {', '.join([str(el) for el in casings])}")
- else:
- print('Bomb Casings: empty')
- for bomb, count in crafted_bombs.items():
- print(f'{bomb}: {count}')
- -----------------------------------------------------------------------------------------------
- # 02. Snake
- def is_inside_func(current_row, current_col):
- return 0 <= current_row < size and 0 <= current_col < size
- def get_next_position_func(direction, row, col):
- if direction == 'up':
- return row - 1, col
- elif direction == 'down':
- return row + 1, col
- elif direction == 'left':
- return row, col - 1
- elif direction == 'right':
- return row, col + 1
- size = int(input())
- burrow_holes = []
- snake_row = 0
- snake_col = 0
- matrix = [] # Square size x size
- for row in range(size):
- matrix.append(list(input()))
- for col in range(size):
- if matrix[row][col] == 'S':
- snake_row = row
- snake_col = col
- elif matrix[row][col] == 'B':
- burrow_holes.append((row, col))
- food = 0
- while True:
- direction = input()
- next_row, next_col = get_next_position_func(direction, snake_row, snake_col)
- matrix[snake_row][snake_col] = '.'
- if is_inside_func(next_row, next_col):
- if matrix[next_row][next_col] == '*':
- matrix[next_row][next_col] = 'S'
- food += 1
- if food >= 10:
- print(f'You won! You fed the snake.')
- break
- elif matrix[next_row][next_col] == 'B':
- matrix[next_row][next_col] = '.'
- burrow_holes.remove((next_row, next_col))
- snake_row, snake_col = burrow_holes[0]
- matrix[snake_row][snake_col] = 'S'
- continue
- else:
- matrix[next_row][next_col] = 'S'
- snake_row, snake_col = next_row, next_col
- else: # Snake is out of the matrix ! break and game over !
- print('Game over!')
- break
- print(f'Food eaten: {food}')
- for el in matrix:
- print(''.join(el))
- -----------------------------------------------------------------------------------------------
- # 03. List Manipulator
- def list_manipulator(nums, *args):
- my_list = nums.copy()
- if args[0] == 'add' and args[1] == 'beginning':
- counter = 0
- for el in args[2:]:
- my_list.insert(counter, el)
- counter += 1
- elif args[0] == 'add' and args[1] == 'end':
- for el in args[2:]:
- my_list.append(el)
- elif args[0] == 'remove' and args[1] == 'end':
- if len(args) == 2:
- my_list.pop()
- else:
- to_remove = args[2]
- while to_remove:
- my_list.pop()
- to_remove -= 1
- elif args[0] == 'remove' and args[1] == 'beginning':
- if len(args) == 2:
- my_list.pop(0)
- else:
- to_remove = args[2]
- while to_remove:
- my_list.pop(0)
- to_remove -= 1
- return my_list
- -----------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement