Spocoman

08. Graduation

Dec 27th, 2021 (edited)
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. name = input()
  2. average_grade = 0
  3. break_point = 0
  4. counter = 1
  5.  
  6. while counter <= 12:
  7.     grade = float(input())
  8.     if grade >= 4:
  9.         average_grade += grade
  10.         counter += 1
  11.     else:
  12.         break_point += 1
  13.  
  14.     if counter == 13:
  15.         print(f'{name} graduated. Average grade: {average_grade / 12:.2f}')
  16.         break
  17.  
  18.     if break_point == 2:
  19.         print(f'{name} has been excluded at {counter} grade')
  20.         break
  21.  
  22. Решение с for:
  23.  
  24. name = input()
  25. average_grade = 0
  26. break_point = 0
  27.  
  28. for i in range(1, 14):
  29.     grade = float(input())
  30.    
  31.     if grade >= 4:
  32.         average_grade += grade
  33.     else:
  34.         break_point += 1
  35.  
  36.     if break_point == 2:
  37.         print(f'{name} has been excluded at {i - 1} grade')
  38.         break
  39.  
  40.     if i - break_point == 12:
  41.         print(f'{name} graduated. Average grade: {average_grade / 12:.2f}')
  42.         break
  43.  
  44.  
  45. Фундаменталс решение:
  46.  
  47. name = input()
  48. grades = []
  49. while True:
  50.     grades.append(float(input()))
  51.     if  len(list(filter(lambda grade: grade < 4, grades))) == 2:
  52.         print(f"{name} has been excluded at {len(grades) -1} grade")
  53.         break
  54.     elif len(list(filter(lambda grade: grade >= 4, grades))) == 12:
  55.         print(f"{name} graduated. Average grade:"
  56.               f" {sum(list(filter(lambda grade: grade >= 4, grades))) / 12:.2f}")
  57.         break
  58.  
Add Comment
Please, Sign In to add comment