Spocoman

06. Cinema Tickets

Dec 30th, 2021 (edited)
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.21 KB | None | 0 0
  1. РЕШЕНИЕ С WHILE:
  2.  
  3. standard_tickets = 0
  4. student_tickets = 0
  5. kid_tickets = 0
  6.  
  7. while True:
  8.     movie = input()
  9.     if movie == 'Finish':
  10.         break
  11.     seats = int(input())
  12.     counter = 0
  13.     while counter != seats:
  14.         category = input()
  15.         if category == 'End':
  16.             break
  17.         if category == 'student':
  18.             student_tickets += 1
  19.         elif category == 'standard':
  20.             standard_tickets += 1
  21.         else:
  22.             kid_tickets += 1
  23.         counter += 1
  24.  
  25.     print(f'{movie} - {counter / seats * 100:.2f}% full.')
  26.  
  27. total_tickets = standard_tickets + student_tickets + kid_tickets
  28. print(f'Total tickets: {total_tickets}')
  29. print(f'{student_tickets / total_tickets * 100:.2f}% student tickets.')
  30. print(f'{standard_tickets / total_tickets * 100:.2f}% standard tickets.')
  31. print(f'{kid_tickets / total_tickets * 100:.2f}% kids tickets.')
  32.  
  33.  
  34. РЕШЕНИЕ С WHILE И FOR:
  35.  
  36. standard_tickets = 0
  37. student_tickets = 0
  38. kid_tickets = 0
  39. movie = input()
  40.  
  41. while movie != 'Finish':
  42.     seats = int(input())
  43.     counter = seats
  44.     for i in range(seats):
  45.         category = input()
  46.         if category == 'End':
  47.             counter = i
  48.             break
  49.         if category == 'student':
  50.             student_tickets += 1
  51.         elif category == 'standard':
  52.             standard_tickets += 1
  53.         else:
  54.             kid_tickets += 1
  55.  
  56.     print(f'{movie} - {counter / seats * 100:.2f}% full.')
  57.     movie = input()
  58.  
  59. total_tickets = standard_tickets + student_tickets + kid_tickets
  60. print(f'Total tickets: {total_tickets}')
  61. print(f'{student_tickets / total_tickets * 100:.2f}% student tickets.')
  62. print(f'{standard_tickets / total_tickets * 100:.2f}% standard tickets.')
  63. print(f'{kid_tickets / total_tickets * 100:.2f}% kids tickets.')
  64.  
  65.  
  66. РЕШЕНИЕ С КОЛЕКЦИЯ:
  67.  
  68. tickets = {"student": 0, "standard": 0, "kid": 0}
  69.  
  70. while True:
  71.     movie = input()
  72.     if movie == 'Finish':
  73.         break
  74.     seats = int(input())
  75.     counter = 0
  76.     while counter != seats:
  77.         category = input()
  78.         if category == 'End':
  79.             break
  80.         tickets[category] += 1
  81.         counter += 1
  82.  
  83.     print(f'{movie} - {counter / seats * 100:.2f}% full.')
  84.  
  85. print(f'Total tickets: {sum(tickets.values())}')
  86. print(f'{tickets["student"] / sum(tickets.values()) * 100:.2f}% student tickets.')
  87. print(f'{tickets["standard"] / sum(tickets.values()) * 100:.2f}% standard tickets.')
  88. print(f'{tickets["kid"] / sum(tickets.values()) * 100:.2f}% kids tickets.')
  89.  
  90.  
  91. ИЛИ:
  92.  
  93. tickets = {"student": 0, "standard": 0, "kid": 0}
  94.  
  95. while True:
  96.     movie = input()
  97.     if movie == 'Finish':
  98.         break
  99.     seats = int(input())
  100.     counter = seats
  101.     for i in range(seats):
  102.         category = input()
  103.         if category == 'End':
  104.             counter = i
  105.             break
  106.         tickets[category] += 1
  107.  
  108.     print(f'{movie} - {counter / seats * 100:.2f}% full.')
  109.  
  110. print(f'Total tickets: {sum(tickets.values())}\n'
  111.       f'{tickets["student"] / sum(tickets.values()) * 100:.2f}% student tickets.\n'
  112.       f'{tickets["standard"] / sum(tickets.values()) * 100:.2f}% standard tickets.\n'
  113.       f'{tickets["kid"] / sum(tickets.values()) * 100:.2f}% kids tickets.')
  114.  
Add Comment
Please, Sign In to add comment