Advertisement
KNenov96

Data Types and Variables - Exercise

Sep 16th, 2022
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.54 KB | None | 0 0
  1. # =========== 01. Integer Operations
  2.  
  3. final_result = 0
  4. for integer in range(1, 4+1):
  5.     num = int(input())
  6.     if integer < 3:
  7.         final_result += num
  8.     elif integer == 3:
  9.         final_result = final_result // num
  10.     else:
  11.         final_result *= num
  12. print(final_result)
  13.  
  14.  
  15.  
  16. # =========== 02. Chars to String
  17.  
  18.  
  19. word = ""
  20. for _ in range(3):
  21.     letter = input()
  22.     word += letter
  23. print(word)
  24.  
  25.  
  26.  
  27. # =========== 03. Elevator
  28.  
  29.  
  30. number_of_people = int(input())
  31. capacity_elevator = int(input())
  32. courses = 0
  33.  
  34. for num in range(0, number_of_people, capacity_elevator):
  35.     courses += 1
  36. print(courses)
  37.  
  38.  
  39.  
  40. # =========== 04. Sum of Chars
  41.  
  42.  
  43. number_of_symbols = int(input())
  44. sum_of_symbols = 0
  45. for symbol in range(number_of_symbols):
  46.     symbol_data = input()
  47.     sum_of_symbols += ord(symbol_data)
  48. print(f"The sum equals: {sum_of_symbols}")
  49.  
  50.  
  51.  
  52. # =========== 05. Print Part of the ASCII Table
  53.  
  54.  
  55. start_index = int(input())
  56. end_index = int(input())
  57.  
  58. for ascii_symbol in range(start_index, end_index+1):
  59.     print(chr(ascii_symbol), end=" ")
  60.  
  61.  
  62. # =========== 06. Triples of Latin Letters
  63.  
  64.  
  65. number_letters = int(input())
  66. end_range = 97 + number_letters
  67.  
  68. for first_letter in range(97, end_range):
  69.     for second_letter in range(97, end_range):
  70.         for third_letter in range(97, end_range):
  71.             print(f"{chr(first_letter)}{chr(second_letter)}{chr(third_letter)}")
  72.  
  73.  
  74. # =========== 07. Water Overflow
  75.  
  76.  
  77. tank_fullness = 0
  78. number_of_lines = int(input())
  79.  
  80. for line in range(number_of_lines):
  81.     water = int(input())
  82.     if water <= 255 - tank_fullness:
  83.         tank_fullness += water
  84.     else:
  85.         print("Insufficient capacity!")
  86. print(tank_fullness)
  87.  
  88. # =========== 08. Party Profit*
  89.  
  90. group_size = int(input())
  91. days_of_adventure = int(input())
  92. coins = 0
  93.  
  94. for day in range(1, days_of_adventure + 1):
  95.     if day % 10 == 0:
  96.         group_size -= 2
  97.     if day % 15 == 0:
  98.         group_size += 5
  99.     coins += 50 - (2 * group_size)  # 50 profit - 2 for food per member
  100.     if day % 3 == 0:
  101.         coins -= 3 * group_size  # spent for water
  102.     if day % 5 == 0:  # boss killing
  103.         coins += 20 * group_size
  104.         if day % 3 == 0:  # if motivational party same day
  105.             coins -= 2 * group_size
  106. print(f"{group_size} companions received {coins//group_size} coins each.")
  107.  
  108.  
  109. # =========== 09. Snowballs*
  110.  
  111.  
  112. snowballs_number = int(input())
  113. value_snowball = 0
  114. parameters_snowball = ""
  115. for snowball in range(snowballs_number):
  116.     weight_snowball = int(input())
  117.     time_to_target = int(input())
  118.     quality_snowball = int(input())
  119.     if (weight_snowball / time_to_target) ** quality_snowball > value_snowball:
  120.         value_snowball = (weight_snowball / time_to_target) ** quality_snowball
  121.         parameters_snowball = f"{weight_snowball} : {time_to_target} = {int(value_snowball)} ({quality_snowball})"
  122. print(parameters_snowball)
  123.  
  124.  
  125. # =========== 10. Gladiator Expenses*
  126.  
  127.  
  128. lost_fights = int(input())
  129. helmet_price = float(input())
  130. sword_price = float(input())
  131. shield_price = float(input())
  132. armor_price = float(input())
  133.  
  134. shield_brake_times = 0
  135. expenses = 0
  136.  
  137. for fight in range(1, lost_fights + 1):
  138.     if fight % 2 == 0:
  139.         expenses += helmet_price
  140.     if fight % 3 == 0:
  141.         expenses += sword_price
  142.         if fight % 2 == 0:
  143.             expenses += shield_price
  144.             shield_brake_times += 1
  145.             if shield_brake_times == 2:
  146.                 expenses += armor_price
  147.                 shield_brake_times = 0
  148. print(f"Gladiator expenses: {expenses:.2f} aureus")
  149.  
  150.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement