Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LIST EXERC -
- ///////////////////////////////////////////////////////////////////////////
- 1
- my_list = input().split()
- new_list = []
- for element in my_list:
- new_list.append(int(element)*-1)
- print(new_list)
- ///////////////////////////////////////////////////////////////////////////
- 2
- factor = int(input())
- count = int(input())
- data = []
- for i in range(1, count + 1):
- data.append(i * factor)
- print(data)
- ///////////////////////////////////////////////////////////////////////////
- 3
- red_cards = input().split(' ')
- team_A = []
- team_B = []
- TOTAL_PLAYERS_IN_TEAM = 11
- is_game_terminated = False
- for player in range(1, TOTAL_PLAYERS_IN_TEAM + 1): #making team_A
- team_A.append("A-" + str(player))
- for player in range(1, TOTAL_PLAYERS_IN_TEAM + 1): #making team_B
- team_B.append("B-" + str(player))
- for card in red_cards:
- if card in team_A:
- team_A.remove(card)
- elif card in team_B:
- team_B.remove(card)
- if len(team_A) < 7 or len(team_B) < 7:
- is_game_terminated = True
- break
- print(f"Team A - {len(team_A)}; Team B - {len(team_B)}")
- if is_game_terminated:
- print(f"Game was terminated")
- ///////////////////////////////////////////////////////////////////////////
- 4
- coins = list(map(int, input().split(",")))
- beggars = int(input())
- list_of_beggars = [0] * beggars
- counter_beggars = 0
- for coin in coins:
- list_of_beggars[counter_beggars] += coin
- counter_beggars += 1
- if counter_beggars >= beggars:
- counter_beggars = 0
- print(list_of_beggars)
- ///////////////////////////////////////////////////////////////////////////
- 5
- card = input().split()
- number_shuffles = int(input())
- half = len(card) // 2
- for shuffles in range(number_shuffles):
- current_shuffle = zip(card[:half], card[half:])
- card.clear()
- for pair in current_shuffle:
- card.extend(pair)
- print(card)
- ///////////////////////////////////////////////////////////////////////////
- 6
- numbers = input().split(' ')
- n = int(input())
- list_as_int = []
- for element in numbers:
- list_as_int.append(int(element))
- for nums in range(1, n + 1):
- list_as_int.remove(min(list_as_int))
- final_result = []
- for element in list_as_int:
- final_result.append(str(element))
- final_print = ', '.join(final_result)
- print(final_print)
- ///////////////////////////////////////////////////////////////////////////
- 7
- gifts_list = input().split(" ")
- command = input()
- while not command == 'No Money':
- if 'OutOfStock' in command:
- command, gift = command.split(" ")
- for current_gift in range(len(gifts_list)):
- if gifts_list[current_gift] == gift:
- gifts_list[current_gift] = 'None'
- elif 'Required' in command:
- command, gift, index = command.split(" ")
- index = int(index)
- if 0 < index < len(gifts_list):
- gifts_list[index] = gift
- elif 'JustInCase' in command:
- command, gift = command.split(" ")
- gifts_list[-1] = gift
- command = input()
- for gifts in range(len(gifts_list)):
- if 'None' in gifts_list:
- gifts_list.remove('None')
- print(' '.join(gifts_list))
- ///////////////////////////////////////////////////////////////////////////
- 8
- HIGH_RANGE = range(81, 126)
- MID_RANGE = range(51, 81)
- LOW_RANGE = range(1, 51)
- fire_data = input().split('#')
- total_water = int(input())
- fire_cells = []
- for every_fire in fire_data:
- fire_range, fire_value = every_fire.split(' = ')
- fire_value = int(fire_value)
- if fire_value > total_water:
- continue
- if fire_range == 'High' and fire_value not in HIGH_RANGE:
- continue
- elif fire_range == 'Medium' and fire_value not in MID_RANGE:
- continue
- elif fire_range == 'Low' and fire_value not in LOW_RANGE:
- continue
- total_water -= fire_value
- fire_cells.append(fire_value)
- print("Cells:")
- for cell in fire_cells:
- print(f" - {cell}")
- effort = sum(fire_cells) * 0.25
- print(f'Effort: {effort:.2f}')
- total_fire = sum(fire_cells)
- print(f"Total Fire: {total_fire}")
- ///////////////////////////////////////////////////////////////////////////
- 9
- items = input().split("|")
- budget = int(input())
- start_budget = budget
- income = []
- profit = 0
- for item in items:
- product, price = item.split('->')
- price = float(price)
- condition = False
- if price > budget:
- continue
- if product == 'Clothes':
- if not 0 <= price <= 50:
- condition = True
- elif product == 'Shoes':
- if not 0 <= price <= 35:
- condition = True
- else:
- if not 0 <= price <= 20.50:
- condition = True
- if not condition:
- budget -= price
- income.append(price + price * 0.40)
- profit += price * 0.40
- for el in income:
- print(f"{el:.2f}", end=' ')
- print()
- print(f"Profit: {profit:.2f}")
- if start_budget + profit >= 150:
- print('Hello, France!')
- else:
- print('Not enough money.')
- ///////////////////////////////////////////////////////////////////////////
- 10
- events = input().split('|')
- energy = 100
- coins = 100
- closed = False
- for event in events:
- action, numbers = event.split('-')
- numbers = int(numbers)
- if action == 'rest':
- temp = energy + numbers
- if temp >= 100:
- print(f'You gained {100 - energy} energy.')
- else:
- print(f'You gained {numbers} energy.')
- energy += numbers
- if energy > 100:
- energy = 100
- print(f'Current energy: {energy}.')
- elif action == 'order':
- if energy < 30:
- energy += 50
- print(f"You had to rest!")
- continue
- coins += numbers
- energy -= 30
- print(f"You earned {numbers} coins.")
- else:
- if coins >= numbers:
- coins -= numbers
- print(f"You bought {action}.")
- else:
- print(f"Closed! Cannot afford {action}.")
- closed = True
- break
- if not closed:
- print(f"Day completed!")
- print(f"Coins: {coins}")
- print(f"Energy: {energy}")
- ///////////////////////////////////////////////////////////////////////////
- Lists Basics - More Exercises !
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
- 1
- numbers = input().split(", ")
- numbers = list(map(int, numbers))
- for zero in numbers:
- if zero == 0:
- numbers.remove(zero)
- numbers.append(0)
- print(numbers)
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
- 2
- numbers = input().split(" ")
- message = input()
- sum_list = []
- for num in numbers:
- numbers_sum = 0
- for i in num:
- numbers_sum += int(i)
- sum_list.append(numbers_sum)
- for index in range(len(sum_list)):
- letter_to_remove = ""
- result = sum_list[index] % len(message)
- letter_to_remove += message[result]
- print(letter_to_remove, end='')
- new_message = message.replace(str(letter_to_remove), "", 1)
- message = new_message
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
- 3
- time = list(map(int, input().split(" ")))
- divisor = len(time)//2
- left_time = time[:divisor]
- right_time = time[:divisor:-1]
- left_racer_time = 0
- for index in range(len(left_time)):
- if left_time[index] == 0:
- left_racer_time *= 0.80
- left_racer_time += left_time[index]
- right_racer_time = 0
- for index in range(len(right_time)):
- if right_time[index] == 0:
- right_racer_time *= 0.80
- right_racer_time += right_time[index]
- if left_racer_time < right_racer_time:
- print(f"The winner is left with total time: {left_racer_time:.1f}")
- else:
- print(f"The winner is right with total time: {right_racer_time:.1f}")
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
- 4
- soldiers = list(map(int, input().split()))
- k = int(input())
- executed = []
- position = k - 1
- index = 0
- len_list = (len(soldiers))
- while len_list > 0:
- index = (position + index) % len_list
- current_killed = (soldiers.pop(index))
- len_list -= 1
- executed.append(current_killed)
- print(str(executed).replace(" ", ""))
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
- 5
- l1 = list(map(int, input().split()))
- l2 = list(map(int, input().split()))
- l3 = list(map(int, input().split()))
- if (l1[0] == 1 and l1[1] == 1 and l1[2] == 1) or (l2[0] == 1 and l2[1] == 1 and l2[2] == 1) or (
- l3[0] == 1 and l3[1] == 1 and l3[2] == 1) or \
- (l1[0] == 1 and l2[1] == 1 and l3[2] == 1) or (l1[2] == 1 and l2[1] == 1 and l3[0] == 1) or (
- l1[0] == 1 and l2[0] == 1 and l3[0] == 1) or \
- (l1[1] == 1 and l2[1] == 1 and l3[1] == 1) or (l1[2] == 1 and l2[2] == 1 and l3[2] == 1):
- print('First player won')
- elif (l1[0] == 2 and l1[1] == 2 and l1[2] == 2) or (l2[0] == 2 and l2[1] == 2 and l2[2] == 2) or (
- l3[0] == 2 and l3[1] == 2 and l3[2] == 2) or \
- (l1[0] == 2 and l2[1] == 2 and l3[2] == 2) or (l1[2] == 2 and l2[1] == 2 and l3[0] == 2) or (
- l1[0] == 2 and l2[0] == 2 and l3[0] == 2) or \
- (l1[1] == 2 and l2[1] == 2 and l3[1] == 2) or (l1[2] == 2 and l2[2] == 2 and l3[2] == 2):
- print('Second player won')
- else:
- print("Draw!")
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
- 6
- import sys
- def is_valid_index(collection: list, index: int):
- if 0 <= index < len(collection):
- return True
- return False
- def exchange_list_at_index(collection: list, index: int):
- exchanged_list = []
- if not is_valid_index(collection, index):
- print('Invalid index')
- exchanged_list = collection
- else:
- left_sub_list = collection[:index + 1]
- right_sub_list = collection[index + 1:]
- for el in right_sub_list:
- exchanged_list.append(el)
- for el in left_sub_list:
- exchanged_list.append(el)
- return exchanged_list
- def max_num_by_criteria(collection: list, custom_filter):
- # Returns the index of max even/odd element by given filter function.
- # It returns -1 if there is no match
- max_element = float('-inf')
- max_element_index = -1
- for i in range(len(collection)):
- num = collection[i]
- if custom_filter(num) and num >= max_element:
- max_element = num
- max_element_index = i
- if max_element_index == -1:
- # No matches found
- print('No matches')
- return max_element_index
- def min_num_by_criteria(collection: list, custom_filter):
- min_element = sys.maxsize
- min_element_index = -1
- for i in range(len(collection)):
- num = collection[i]
- if custom_filter(num) and num <= min_element:
- min_element = num
- min_element_index = i
- if min_element_index == -1:
- print('No matches')
- return min_element_index
- def first_count_elements_by_criteria(collection: list, count: int, custom_filter):
- if count > len(collection):
- print('Invalid count')
- else:
- matching_elements = []
- for num in collection:
- if custom_filter(num) and len(matching_elements) < count:
- matching_elements.append(num)
- print(matching_elements)
- def last_count_elements_by_criteria(collection: list, count: int, custom_filter):
- if count > len(collection):
- print('Invalid count')
- else:
- matching_elements = []
- for i in range(len(collection) - 1, -1, -1):
- num = collection[i]
- if custom_filter(num) and len(matching_elements) < count:
- matching_elements.append(num)
- print(matching_elements[::-1])
- def parse_collection_to_int(collection: list):
- parsed_collection = []
- for el in collection:
- parsed_collection.append(int(el))
- return parsed_collection
- def stringify_collection(collection: list, delimiter: str):
- parsed_collection = []
- for num in collection:
- parsed_collection.append(str(num))
- return delimiter.join(parsed_collection)
- elements = input().split()
- numbers = parse_collection_to_int(elements)
- command = input()
- while command != "end":
- cmd_args = command.split()
- cmd_type = cmd_args[0]
- if cmd_type == "exchange":
- index = int(cmd_args[1])
- numbers = exchange_list_at_index(numbers, index)
- elif cmd_type == "max":
- cmd_filter = cmd_args[1]
- max_index = -1
- if cmd_filter == "even":
- max_index = max_num_by_criteria(numbers, lambda n: n % 2 == 0)
- elif cmd_filter == "odd":
- max_index = max_num_by_criteria(numbers, lambda n: n % 2 != 0)
- if max_index != -1:
- print(max_index)
- elif cmd_type == "min":
- cmd_filter = cmd_args[1]
- min_index = -1
- if cmd_filter == "even":
- min_index = min_num_by_criteria(numbers, lambda n: n % 2 == 0)
- elif cmd_filter == "odd":
- min_index = min_num_by_criteria(numbers, lambda n: n % 2 != 0)
- if min_index != -1:
- print(min_index)
- elif cmd_type == "first":
- count = int(cmd_args[1])
- cmd_filter = cmd_args[2]
- if cmd_filter == "even":
- first_count_elements_by_criteria(numbers, count, lambda n: n % 2 == 0)
- elif cmd_filter == "odd":
- first_count_elements_by_criteria(numbers, count, lambda n: n % 2 != 0)
- elif cmd_type == "last":
- count = int(cmd_args[1])
- cmd_filter = cmd_args[2]
- if cmd_filter == "even":
- last_count_elements_by_criteria(numbers, count, lambda n: n % 2 == 0)
- elif cmd_filter == "odd":
- last_count_elements_by_criteria(numbers, count, lambda n: n % 2 != 0)
- command = input()
- print(f'[{stringify_collection(numbers, ", ")}]')
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement