Advertisement
KNenov96

Lists Basics - Exercise

Sep 17th, 2022
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.86 KB | None | 0 0
  1. # ========== 01. Invert Values
  2.  
  3. values = list(map(int, input().split(" ")))
  4. print([-x for x in values])
  5.  
  6. # ========== 02. Multiples List
  7.  
  8. factor = int(input())
  9. count = int(input())
  10. multiplies = [factor]
  11.  
  12. for _ in range(1, count):
  13.     multiplies.append(factor + multiplies[-1])
  14. print(multiplies)
  15.  
  16.  
  17. # ========== 03. Football Cards
  18.  
  19. sequence_of_cards = input().split()
  20.  
  21. total_players_team_a = 11
  22. total_players_team_b = 11
  23.  
  24. removed_players_team_a = []
  25. removed_players_team_b = []
  26.  
  27. game_is_terminated = False
  28.  
  29. for given_card in sequence_of_cards:
  30.     given_card = given_card.split("-")
  31.     team = given_card[0]
  32.     player = given_card[1]
  33.     if team == "A":
  34.         if player not in removed_players_team_a:
  35.             total_players_team_a -= 1
  36.             removed_players_team_a.append(player)
  37.     elif team == "B":
  38.         if player not in removed_players_team_b:
  39.             total_players_team_b -= 1
  40.             removed_players_team_b.append(player)
  41.     if total_players_team_b < 7 or total_players_team_a < 7:
  42.         game_is_terminated = True
  43.         break
  44. print(f"Team A - {total_players_team_a}; Team B - {total_players_team_b}")
  45. if game_is_terminated:
  46.     print("Game was terminated")
  47.  
  48.  
  49. # ========== 04. Number Beggars
  50.  
  51.  
  52. numbers_for_robbing = list(map(int, input().split(", ")))
  53. numbers_of_beggars = int(input())
  54.  
  55. lst_beggars = [0] * numbers_of_beggars
  56. counter = 0
  57.  
  58. for number in range(len(numbers_for_robbing)):
  59.     lst_beggars[counter] += numbers_for_robbing[number]
  60.     counter += 1
  61.     if counter >= numbers_of_beggars:
  62.         counter = 0
  63. print(lst_beggars)
  64.  
  65.  
  66. # ========== 05. Faro Shuffle
  67.  
  68. deck_of_symbols = input().split()
  69. middle_of_deck = len(deck_of_symbols) // 2
  70.  
  71. first_half_deck = deck_of_symbols[:middle_of_deck]  # slicing in half
  72. second_half_deck = deck_of_symbols[middle_of_deck:]  # slicing in half
  73.  
  74. faro_shuffle_times = int(input())
  75.  
  76. for shuffle in range(faro_shuffle_times):
  77.     shuffled_deck = []
  78.     for cards in range(middle_of_deck):
  79.         shuffled_deck.append(first_half_deck[cards])
  80.         shuffled_deck.append(second_half_deck[cards])
  81.     first_half_deck = shuffled_deck[:middle_of_deck]
  82.     second_half_deck = shuffled_deck[middle_of_deck:]
  83. print(shuffled_deck)
  84.  
  85.  
  86. # ========== 06. Survival of the Biggest
  87.  
  88. lst_of_numbers = list(map(int, input().split()))
  89. numbers_to_remove = int(input())
  90.  
  91. for num in range(numbers_to_remove):
  92.     smallest = min(lst_of_numbers)
  93.     lst_of_numbers.remove(smallest)
  94. print(", ".join(str(x) for x in lst_of_numbers))
  95.  
  96.  
  97. # ========== 07. Easter Gifts
  98.  
  99. gifts = input().split()
  100. command = input()
  101.  
  102. while command != "No Money":
  103.     command = command.split()
  104.     if command[0] == "OutOfStock":
  105.         for gift in range(len(gifts)):
  106.             if gifts[gift] == command[1]:
  107.                 gifts[gift] = "None"
  108.     elif command[0] == "Required":
  109.         if 0 < int(command[2]) < len(gifts):
  110.             gifts[int(command[2])] = command[1]
  111.     elif command[0] == "JustInCase":
  112.         gifts[-1] = command[1]
  113.     command = input()
  114. print(" ".join(x for x in gifts if x != "None"))
  115.  
  116.  
  117. # ========== 08. Seize the Fire
  118.  
  119. type_of_fire = input().split("#")
  120. amount_of_water = int(input())
  121. cells_extinguished = []
  122. effort = 0
  123.  
  124. for fire in type_of_fire:
  125.     fire = fire.split(" = ")
  126.     type_current_fire = fire[0]
  127.     power_current_fire = int(fire[1])
  128.     if power_current_fire <= amount_of_water:
  129.         if type_current_fire == "High":
  130.             if 81 <= power_current_fire <= 125:
  131.                 amount_of_water -= power_current_fire
  132.                 effort += power_current_fire * 0.25
  133.                 cells_extinguished.append(power_current_fire)
  134.         elif type_current_fire == "Medium":
  135.             if 51 <= power_current_fire <= 80:
  136.                 amount_of_water -= power_current_fire
  137.                 effort += power_current_fire * 0.25
  138.                 cells_extinguished.append(power_current_fire)
  139.         elif type_current_fire == "Low":
  140.             if 1 <= power_current_fire <= 50:
  141.                 amount_of_water -= power_current_fire
  142.                 effort += power_current_fire * 0.25
  143.                 cells_extinguished.append(power_current_fire)
  144.  
  145. print("Cells:")
  146. for cell in cells_extinguished:
  147.     print(f" - {cell}")
  148. print(f"Effort: {effort:.2f}")
  149. print(f"Total Fire: {sum(cells_extinguished)}")
  150.  
  151.  
  152. # ========== 09. Hello, France
  153.  
  154. items_for_sale = input().split("|")
  155. budget = float(input())
  156. new_item_prices = []
  157. old_item_prices = []
  158.  
  159. for item in items_for_sale:
  160.     current_item = item.split("->")[0]
  161.     price_item = float(item.split("->")[1])
  162.     if current_item == "Clothes" and price_item <= 50:
  163.         if budget >= price_item:
  164.             budget -= price_item
  165.             new_item_prices.append(price_item+(price_item*0.4))
  166.             old_item_prices.append(price_item)
  167.     elif current_item == "Shoes" and price_item <= 35:
  168.         if budget >= price_item:
  169.             budget -= price_item
  170.             new_item_prices.append(price_item + (price_item * 0.4))
  171.             old_item_prices.append(price_item)
  172.     elif current_item == "Accessories" and price_item <= 20.50:
  173.         if budget >= price_item:
  174.             budget -= price_item
  175.             new_item_prices.append(price_item + (price_item * 0.4))
  176.             old_item_prices.append(price_item)
  177.  
  178. profit = sum(new_item_prices) - sum(old_item_prices)
  179. print(" ".join(f"{x:.2f}" for x in new_item_prices))
  180. print(f"Profit: {profit:.2f}")
  181. if budget + sum(new_item_prices) >= 150:
  182.     print("Hello, France!")
  183. else:
  184.     print("Not enough money.")
  185.  
  186.  
  187. # ========== 10. Bread Factory
  188.  
  189. working_events = input().split("|")
  190. energy = 100
  191. coins = 100
  192. gained_energy = 0
  193. bakery_open = True
  194.  
  195. for day in working_events:
  196.     event = day.split("-")[0]
  197.     amount_of_event = int(day.split("-")[1])
  198.     if event == "rest":
  199.         energy += amount_of_event
  200.         if energy <= 100:
  201.             print(f"You gained {amount_of_event} energy.")
  202.             print(f"Current energy: {energy}.")
  203.         else:
  204.             gained_energy = abs(amount_of_event - (energy - 100))
  205.             if energy > 100:
  206.                 energy = 100
  207.             print(f"You gained {gained_energy} energy.")
  208.             print(f"Current energy: {energy}.")
  209.     elif event == "order":
  210.         if energy >= 30:
  211.             energy -= 30
  212.             coins += amount_of_event
  213.             print(f"You earned {amount_of_event} coins.")
  214.         else:
  215.             print("You had to rest!")
  216.             energy += 50
  217.             if energy > 100:
  218.                 energy = 100
  219.     else:
  220.         if coins >= amount_of_event:
  221.             coins -= amount_of_event
  222.             print(f"You bought {event}.")
  223.         else:
  224.             print(f"Closed! Cannot afford {event}.")
  225.             bakery_open = False
  226.             break
  227.  
  228. if bakery_open:
  229.     print("Day completed!")
  230.     print(f"Coins: {coins}")
  231.     print(f"Energy: {energy}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement