Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = int(input())
- p1 = 0
- p2 = 0
- p3 = 0
- p4 = 0
- p5 = 0
- for i in range(n):
- p = int(input())
- if p < 200:
- p1 += 1
- elif 200 <= p < 400:
- p2 += 1
- elif 400 <= p < 600:
- p3 += 1
- elif 600 <= p < 800:
- p4 += 1
- else:
- p5 += 1
- print(f'{p1 / n * 100:.2f}%')
- print(f'{p2 / n * 100:.2f}%')
- print(f'{p3 / n * 100:.2f}%')
- print(f'{p4 / n * 100:.2f}%')
- print(f'{p5 / n * 100:.2f}%')
- Решение с list() и тернарен оператор:
- parameters = {'p1': 0, 'p2': 0, 'p3': 0, 'p4': 0, 'p5': 0}
- n = int(input())
- for i in range(n):
- p = int(input())
- parameters['p5' if p >= 800 else 'p4' if p >= 600 else 'p3' if p >= 400 else 'p2' if p >= 200 else 'p1'] += 1
- for p in parameters.values():
- print(f'{p / n * 100:.2f}%')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement