Advertisement
KNenov96

Basic Syntax, Cond Statements and Loops.Exercise

Sep 15th, 2022
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.83 KB | None | 0 0
  1. # 01. Jenny's Secret Message
  2.  
  3. def hello(name):
  4.     if name != "Johnny":
  5.         print(f"Hello, {name}!")
  6.     else:
  7.         print(f"Hello, my love!")
  8.  
  9. hello(input())
  10.  
  11.  
  12. # 02. Drink Something
  13.  
  14. age = int(input())
  15.  
  16. if age <= 14:
  17.     print("drink toddy")
  18. elif age <= 18:
  19.     print("drink coke")
  20. elif age <= 21:
  21.     print("drink beer")
  22. elif age > 21:
  23.     print("drink whisky")
  24.  
  25.  
  26. # 03. Chat Codes
  27.  
  28. number_lines = int(input())
  29.  
  30. for line in range(number_lines):
  31.     message = int(input())
  32.  
  33.     if message == 88:
  34.         print("Hello")
  35.     elif message == 86:
  36.         print("How are you?")
  37.     elif message < 88:
  38.         print("GREAT!")
  39.     else:
  40.         print("Bye.")
  41.  
  42.  
  43. # 04. Maximum Multiple
  44.  
  45. divisor = int(input())
  46. bound = int(input())
  47.  
  48. max_num = 0
  49.  
  50. for num in range(1, bound+1):
  51.     if num % divisor == 0:
  52.         max_num = num
  53.  
  54. print(max_num)
  55.  
  56.  
  57. # 05. Orders
  58.  
  59. number_orders = int(input())
  60. total_price = 0
  61.  
  62. for orders in range(number_orders):
  63.     price_capsule = float(input())
  64.     days = int(input())
  65.     capsules_per_day = int(input())
  66.     rules = [0.01 <= price_capsule <= 100, 1 <= days <= 31,
  67.              1 <= capsules_per_day <= 2000]
  68.     if not all(rules):
  69.         continue
  70.     current_price = (days * capsules_per_day) * price_capsule
  71.     total_price += current_price
  72.     print(f"The price for the coffee is: ${current_price:.2f}")
  73. print(f"Total: ${total_price:.2f}")
  74.  
  75.  
  76. # 06. String Pureness
  77.  
  78. number_of_strings = int(input())
  79. non_pure_symbols = [".", ",", "_"]
  80. pureness = True
  81.  
  82. for string in range(number_of_strings):
  83.     data_check = input()
  84.     for symbol in non_pure_symbols:
  85.         if symbol in data_check:
  86.             pureness = False
  87.     if pureness:
  88.         print(f"{data_check} is pure.")
  89.     else:
  90.         print(f"{data_check} is not pure!")
  91.  
  92.     pureness = True
  93.  
  94.  
  95. # 07. 07. Double Char
  96.  
  97. receive_data = input()
  98. new_word = ""
  99. while receive_data != "End":
  100.     if receive_data != "SoftUni":
  101.         for letter in receive_data:
  102.             new_word += letter+letter
  103.         print(new_word)
  104.     receive_data = input()
  105.     new_word = ""
  106.  
  107.  
  108. # 08. How Much Coffee Do You Need?
  109.  
  110. awake_info = input()
  111. coffee_cups = 0
  112.  
  113. while awake_info != "END":
  114.     if awake_info in ["cat", "dog", "movie", "coding"]:
  115.         coffee_cups += 1
  116.     elif awake_info in ["CAT", "DOG", "MOVIE", "CODING"]:
  117.         coffee_cups += 2
  118.     awake_info = input()
  119.  
  120. if coffee_cups > 5:
  121.     print("You need extra sleep")
  122. else:
  123.     print(coffee_cups)
  124.  
  125.  
  126. # 09. Sorting Hat
  127.  
  128. name = input()
  129.  
  130. while name != "Welcome!":
  131.     if name == "Voldemort":
  132.         print("You must not speak of that name!")
  133.         break
  134.  
  135.     if len(name) < 5:
  136.         print(f"{name} goes to Gryffindor.")
  137.     elif len(name) == 5:
  138.         print(f"{name} goes to Slytherin.")
  139.     elif len(name) == 6:
  140.         print(f"{name} goes to Ravenclaw.")
  141.     elif len(name) > 6:
  142.         print(f"{name} goes to Hufflepuff.")
  143.  
  144.     name = input()
  145.  
  146. if name == "Welcome!":
  147.     print("Welcome to Hogwarts.")
  148.  
  149. # 10. Mutate Strings
  150.  
  151. first_word = input()
  152. second_word = input()
  153. already_mutated = [first_word]
  154. mutated_word = ""
  155.  
  156. for letter in range(len(first_word)):
  157.     mutated_word = second_word[:letter+1]+first_word[letter+1:]
  158.     if mutated_word not in already_mutated:
  159.         print(mutated_word)
  160.         already_mutated.append(mutated_word)
  161.  
  162. # 11.Easter Bread
  163.  
  164. cooking_budget = float(input())
  165. price_for_flour = float(input())
  166.  
  167. price_one_pack_eggs = price_for_flour * 0.75
  168. milk_liter_price = (price_for_flour * 0.25) + price_for_flour
  169.  
  170. one_bread_price = price_one_pack_eggs + price_for_flour + (milk_liter_price*0.25)
  171. loaves = cooking_budget // one_bread_price
  172. colored_eggs = 0
  173.  
  174. for count in range(1, int(loaves) +1):
  175.     colored_eggs += 3
  176.     if count % 3 == 0:
  177.         colored_eggs -= count - 2
  178.  
  179. print(f"You made {int(loaves)} loaves of Easter bread! Now you have {colored_eggs} eggs and "
  180.       f"{cooking_budget - (loaves * one_bread_price):.2f}BGN left.")
  181.  
  182.  
  183. # 12.Christmast Spirit
  184.  
  185. quantity_of_decorations = int(input())
  186. days_till_christmas = int(input())
  187. christmas_spirit = 0
  188. shopping_costs = 0
  189.  
  190. for day in range(1, days_till_christmas +1):
  191.     if day % 11 == 0:
  192.         quantity_of_decorations += 2
  193.     if day % 2 == 0:
  194.         shopping_costs += 2 * quantity_of_decorations
  195.         christmas_spirit += 5
  196.     if day % 3 == 0:
  197.         shopping_costs += 8 * quantity_of_decorations
  198.         christmas_spirit += 13
  199.     if day % 5 == 0:
  200.         shopping_costs += 15 * quantity_of_decorations
  201.         christmas_spirit += 17
  202.         if day % 3 == 0:
  203.             christmas_spirit += 30
  204.     if day % 10 == 0:
  205.         shopping_costs += 23
  206.         christmas_spirit -= 20
  207.         if days_till_christmas == day:
  208.             christmas_spirit -= 30
  209. print(f"Total cost: {shopping_costs}")
  210. print(f"Total spirit: {christmas_spirit}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement