veronikaaa86

03. Histogram

Mar 20th, 2022 (edited)
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. n = int(input())
  2.  
  3. p1 = 0
  4. p2 = 0
  5. p3 = 0
  6. p4 = 0
  7. p5 = 0
  8. for i in range(1, n + 1):
  9.     current_num = int(input())
  10.  
  11.     if current_num < 200:
  12.         p1 = p1 + 1
  13.     elif current_num <= 399:
  14.         p2 = p2 + 1
  15.     elif current_num <= 599:
  16.         p3 = p3 + 1
  17.     elif current_num <= 799:
  18.         p4 = p4 + 1
  19.     else:
  20.         p5 = p5 + 1
  21.  
  22. p1_percent = p1 / n * 100
  23. p2_percent = p2 / n * 100
  24. p3_percent = p3 / n * 100
  25. p4_percent = p4 / n * 100
  26. p5_percent = p5 / n * 100
  27.  
  28. print(f"{p1_percent:.2f}%")
  29. print(f"{p2_percent:.2f}%")
  30. print(f"{p3_percent:.2f}%")
  31. print(f"{p4_percent:.2f}%")
  32. print(f"{p5_percent:.2f}%")
Add Comment
Please, Sign In to add comment