GalinaKG

Basic Syntax, Conditional Statements and Loops - Exercise

Jun 2nd, 2022
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.48 KB | None | 0 0
  1. 06. String Pureness
  2.  
  3. number = int(input())
  4.  
  5. for string in range(number):
  6.     word = input()
  7.     if ',' in word or '.' in word or '_' in word:
  8.         print(f'{word} is not pure!')
  9.     else:
  10.         print(f'{word} is pure.')
  11.  
  12. 07. Double Char
  13.  
  14. command = input()
  15.  
  16. while command != "End":
  17.     strings = command
  18.  
  19.     if strings == "SoftUni":
  20.         command = input()
  21.         continue
  22.  
  23.     result = ""
  24.  
  25.     for i in range(len(strings)):
  26.         char = strings[i]
  27.         result += char * 2
  28.  
  29.     print(result)
  30.     command = input()
  31.  
  32. 08. How Much Coffee Do You Need?
  33.  
  34. command = input()
  35. coffee = 0
  36.  
  37. while command != "END":
  38.     events = command
  39.  
  40.     if events.lower() == "coding" or events.lower() == "dog" or events.lower() == "cat" or events.lower() == "movie":
  41.         if events.islower():
  42.             coffee += 1
  43.         if events.isupper():
  44.             coffee += 2
  45.     else:
  46.         pass
  47.  
  48.     command = input()
  49.  
  50. if coffee <= 5:
  51.     print(coffee)
  52. else:
  53.     print("You need extra sleep")
  54.  
  55. 09. Sorting Hat
  56.  
  57. command = input()
  58. is_success = False
  59.  
  60. while command != "Welcome!":
  61.     name = command
  62.     is_success = False
  63.  
  64.     if name == "Voldemort":
  65.         print("You must not speak of that name!")
  66.         break
  67.     else:
  68.         is_success = True
  69.  
  70.     if len(name) < 5:
  71.         print(f"{name} goes to Gryffindor.")
  72.     elif len(name) == 5:
  73.         print(f"{name} goes to Slytherin.")
  74.     elif len(name) == 6:
  75.         print(f"{name} goes to Ravenclaw.")
  76.     else:
  77.         print(f"{name} goes to Hufflepuff.")
  78.  
  79.     command = input()
  80.  
  81. if is_success:
  82.     print("Welcome to Hogwarts.")
  83.  
  84. 10. Mutate Strings
  85.  
  86. first_string = input()
  87. second_string = input()
  88. last_string = first_string
  89.  
  90. for symbol in range(len(first_string)):
  91.     left_part = second_string[:symbol + 1] # [0:symbol + 1:1]
  92.     right_part = first_string[symbol + 1:] # [0:len(first_string):1]
  93.     current_string = left_part + right_part
  94.  
  95.     if current_string == last_string:
  96.         continue
  97.     print(current_string)
  98.     last_string = current_string
  99.  
  100. 11. Easter Bread
  101.  
  102. budget = float(input())
  103. kg_flour_price = float(input())
  104. one_pack_of_eggs_price = kg_flour_price * 0.75
  105. liter_milk = kg_flour_price + (kg_flour_price * 0.25)
  106. recipe = one_pack_of_eggs_price + kg_flour_price + (liter_milk * 0.250)
  107. colored_eggs = 0
  108. counter_breads = 0
  109.  
  110. while budget > recipe:
  111.     budget -= recipe
  112.     colored_eggs += 3
  113.     counter_breads += 1
  114.  
  115.     if counter_breads % 3 == 0:
  116.         colored_eggs -= (counter_breads - 2)
  117.  
  118. print(f"You made {counter_breads} loaves of Easter bread! Now you have {colored_eggs} eggs and {budget:.2f}BGN left.")
  119.  
  120. 12. Christmas Spirit
  121.  
  122. quantity = int(input())
  123. days = int(input())
  124.  
  125. christmas_spirit = 0
  126. total_costs = 0
  127. condition_5_day = False
  128.  
  129. for day in range(1, days + 1):
  130.     condition_5_day = False
  131.  
  132.     if day % 11 == 0:
  133.         quantity += 2
  134.  
  135.     if day % 2 == 0:
  136.         christmas_spirit += 5
  137.         total_costs += 2 * quantity
  138.  
  139.     if day % 3 == 0:
  140.         christmas_spirit += 13
  141.         total_costs += (5 * quantity) + (3 * quantity)
  142.         condition_5_day = True
  143.  
  144.     if day % 5 == 0:
  145.         christmas_spirit += 17
  146.         total_costs += quantity * 15
  147.  
  148.         if condition_5_day:
  149.             christmas_spirit += 30
  150.  
  151.     if day % 10 == 0:
  152.         christmas_spirit -= 20
  153.         total_costs += 23
  154.  
  155.         if day == days:
  156.             christmas_spirit -= 30
  157.  
  158. print(f'Total cost: {total_costs}')
  159. print(f'Total spirit: {christmas_spirit}')
Advertisement
Add Comment
Please, Sign In to add comment