Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- For-Loop - More Exercises
- 08. Equal Pairs
- ******************************************
- twins = int(input())
- total_sum = 0
- z1 = 0
- z2 = 0
- for number in range(1, twins+1):
- x = int(input())
- y = int(input())
- total_sum += x + y
- if total_sum == x+y:
- z1 = total_sum
- if total_sum != x+y:
- z2 = x+y
- if number == 1:
- print(f"Yes, value={x+y}")
- elif x+y == z2 and x+y == z1:
- print(f"Yes, value={x+y}")
- else:
- print(f"No, maxdiff={abs(z2-z1)}")
- ****************************************
- While Loop - Lab
- 08. Graduation
- name_student = input()
- counter_years = 0
- counter_fails = 0
- total_years = 0
- sum_grades = 0
- current_grade = 0
- while counter_fails != 2:
- current_grade = float(input())
- if current_grade >= 4:
- sum_grades += current_grade
- counter_years += 1
- elif current_grade < 4:
- counter_fails += 1
- total_years = counter_years + counter_fails
- if total_years == 12 and counter_fails != 2:
- print(f"{name_student} graduated. Average grade: {(sum_grades / total_years):.2f}")
- break
- elif counter_fails == 2:
- print(f"{name_student} has been excluded at {total_years-1} grade")
- *********************************************************************************************
- For-Loop - More Exercises
- 11. Odd / Even Position
- even_min_number = 100000000000000000000000
- odd_min_number = 100000000000000000000000
- even_max_number = -1000000000000000000000
- odd_max_number = -1000000000000000000000
- n = int(input())
- even_sum = 0
- odd_sum = 0
- for i in range(1, n+1):
- number = float(input())
- if i % 2 == 0:
- if number < even_min_number:
- even_min_number = number
- if number > even_max_number:
- even_max_number = number
- even_sum += number
- if i == 0:
- even_min_number = 0
- even_max_number = 0
- if i % 2 != 0:
- if number < odd_min_number:
- odd_min_number = number
- if number > odd_max_number:
- odd_max_number = number
- odd_sum += number
- if i == 0:
- odd_max_number = 0
- odd_min_number = 0
- print(f"OddSum={odd_sum:.2f},")
- print(f"OddMin={odd_min_number:.2f},")
- print(f"OddMax={odd_max_number:.2f},")
- print(f"EvenSum={even_sum:.2f},")
- print(f"EvenMin={even_min_number:.2f},")
- print(f"EvenMax={even_max_number:.2f}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement