Advertisement
GeorgiLukanov87

3_problems

Mar 15th, 2022
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.39 KB | None | 0 0
  1. For-Loop - More Exercises
  2. 08. Equal Pairs
  3.  
  4. ******************************************
  5. twins = int(input())
  6. total_sum = 0
  7. z1 = 0
  8. z2 = 0
  9.  
  10. for number in range(1, twins+1):
  11.     x = int(input())
  12.     y = int(input())
  13.     total_sum += x + y
  14.  
  15.     if total_sum == x+y:
  16.         z1 = total_sum
  17.  
  18.     if total_sum != x+y:
  19.         z2 = x+y
  20. if number == 1:
  21.     print(f"Yes, value={x+y}")
  22. elif x+y == z2 and x+y == z1:
  23.     print(f"Yes, value={x+y}")
  24. else:
  25.     print(f"No, maxdiff={abs(z2-z1)}")
  26.  
  27.  
  28. ****************************************
  29.  
  30. While Loop - Lab
  31. 08. Graduation
  32.  
  33. name_student = input()
  34. counter_years = 0
  35. counter_fails = 0
  36. total_years = 0
  37. sum_grades = 0
  38. current_grade = 0
  39.  
  40. while counter_fails != 2:
  41.     current_grade = float(input())
  42.     if current_grade >= 4:
  43.         sum_grades += current_grade
  44.         counter_years += 1
  45.     elif current_grade < 4:
  46.         counter_fails += 1
  47.     total_years = counter_years + counter_fails
  48.     if total_years == 12 and counter_fails != 2:
  49.         print(f"{name_student} graduated. Average grade: {(sum_grades / total_years):.2f}")
  50.         break
  51.     elif counter_fails == 2:
  52.         print(f"{name_student} has been excluded at {total_years-1} grade")
  53.  
  54. *********************************************************************************************
  55.  
  56. For-Loop - More Exercises
  57. 11. Odd / Even Position
  58.  
  59.  
  60. even_min_number = 100000000000000000000000
  61. odd_min_number = 100000000000000000000000
  62. even_max_number = -1000000000000000000000
  63. odd_max_number = -1000000000000000000000
  64. n = int(input())
  65. even_sum = 0
  66. odd_sum = 0
  67.  
  68. for i in range(1, n+1):
  69.     number = float(input())
  70.     if i % 2 == 0:
  71.         if number < even_min_number:
  72.             even_min_number = number
  73.         if number > even_max_number:
  74.             even_max_number = number
  75.         even_sum += number
  76.     if i == 0:
  77.         even_min_number = 0
  78.         even_max_number = 0
  79.     if i % 2 != 0:
  80.         if number < odd_min_number:
  81.             odd_min_number = number
  82.         if number > odd_max_number:
  83.             odd_max_number = number
  84.         odd_sum += number
  85.     if i == 0:
  86.         odd_max_number = 0
  87.         odd_min_number = 0
  88.  
  89. print(f"OddSum={odd_sum:.2f},")
  90. print(f"OddMin={odd_min_number:.2f},")
  91. print(f"OddMax={odd_max_number:.2f},")
  92.  
  93. print(f"EvenSum={even_sum:.2f},")
  94. print(f"EvenMin={even_min_number:.2f},")
  95. print(f"EvenMax={even_max_number:.2f}")
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement