Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 02. Programming Fundamentals Final Exam with FUNCTIONS ! 300/300
- # https://judge.softuni.org/Contests/Practice/Index/2518#2
- ## 01. World Tour
- ## 02. Destination Mapper
- ## 03. Plant Discovery
- ======================================================================================================
- # 01. World Tour
- def is_index_valid(some_index, some_data):
- if 0 <= some_index < len(some_data):
- return True
- return False
- def add_stop_func(main_data, some_data):
- index = int(main_data[1])
- string = main_data[2]
- if is_index_valid(index, some_data):
- some_data = some_data[:index] + string + some_data[index:]
- print(some_data)
- return some_data
- def remove_stop_func(main_data, some_data):
- start_index = int(main_data[1])
- end_index = int(main_data[2])
- if is_index_valid(start_index, some_data) and is_index_valid(end_index, some_data):
- to_remove = some_data[start_index:end_index + 1]
- some_data = some_data.replace(to_remove, "")
- print(some_data)
- return some_data
- def switch_func(main_data, some_data):
- old_string = main_data[1]
- new_string = main_data[2]
- if old_string in some_data:
- some_data = some_data.replace(old_string, new_string)
- print(some_data)
- return some_data
- data = input()
- command = input()
- while not command == 'Travel':
- details = command.split(":")
- if details[0] == 'Add Stop':
- data = add_stop_func(details, data)
- elif details[0] == 'Remove Stop':
- data = remove_stop_func(details, data)
- elif details[0] == 'Switch':
- data = switch_func(details, data)
- command = input()
- print(f"Ready for world tour! Planned stops: {data}")
- ======================================================================================================
- # 02. Destination Mapper
- def extract_datas(some_pattern, some_data):
- all_destinations = []
- travel_points = 0
- matched = re.findall(patter, data)
- for match in matched:
- current_destination = match[1]
- all_destinations.append(current_destination)
- for _ in current_destination:
- travel_points += 1
- return all_destinations, travel_points
- import re
- data = input()
- patter = r'(\=|\/)([A-Z][a-zA-Z]{2,})\1'
- result, total_travel_points = extract_datas(patter, data)
- print(f'Destinations: {", ".join(result)}')
- print(f'Travel Points: {total_travel_points}')
- ======================================================================================================
- # 03. Plant Discovery
- def create_plant_dict_func(plants_number):
- initial_plants = {}
- for _ in range(plants_number):
- info = input().split('<->')
- current_name = info[0]
- rarity = int(info[1])
- initial_plants[current_name] = {'rarity': rarity, 'rating': 0}
- return initial_plants
- def rate_func(some_details, some_plants):
- current_name = some_details[1]
- rating = int(some_details[-1])
- if some_plants[current_name]['rating'] == 0:
- some_plants[current_name]['rating'] += rating
- else:
- some_plants[current_name]['rating'] += rating
- some_plants[current_name]['rating'] /= 2
- return some_plants
- def update_func(some_details, some_plants):
- current_name = some_details[1]
- new_rarity = int(some_details[-1])
- some_plants[current_name]['rarity'] = new_rarity
- return some_plants
- def reset_func(some_details, some_plants):
- current_name = some_details[1]
- some_plants[current_name]['rating'] = 0
- return some_plants
- n = int(input())
- plants = create_plant_dict_func(n)
- command = input()
- while not command == 'Exhibition':
- details = command.split()
- if details[1] not in plants:
- print('error')
- command = input()
- continue
- else:
- if details[0] == 'Rate:':
- plants = rate_func(details, plants)
- elif details[0] == 'Update:':
- plants = update_func(details, plants)
- elif details[0] == 'Reset:':
- plants = reset_func(details, plants)
- command = input()
- print('Plants for the exhibition:')
- for name, v in plants.items():
- print(f'- {name}; Rarity: {plants[name]["rarity"]}; Rating: {plants[name]["rating"]:.2f}')
- ======================================================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement