51.5k views
1 vote
You need to control the number of people who can be in an oyster bar at the same time. Groups of people can always leave the bar, but a group cannot enter the bar if they would make the number of people in the bar exceed the maximum of 100 occupants. Write a program that reads the sizes of the groups that arrive or depart. Use negative numbers for departures. After each input, display the current number of occupants. As soon as the bar holds the maximum number of people, report that the bar is full and exit the program.

User ZachRabbit
by
4.5k points

1 Answer

3 votes

Answer:

count = 0

while True:

people = int(input("Enter the number of people arrived/departed: "))

count += people

if count == 100:

print("The bar is full")

break

elif count < 100:

print("There are " + str(count) + " in the bar currently")

else:

print(str(people) + " people cannot enter right now")

print("The maximum capacity is 100!")

count -= people

print("There are " + str(count) + " in the bar currently")

Step-by-step explanation:

*The code is in Python.

Set the count as 0

Create an indefinite while loop.

Inside the loop:

Ask the user to enter the number of people arrived/departed

Add the people to the count (cumulative sum)

Check the count. If the count is 100, stop the loop. If the count is smaller than 100, print the current number of people. Otherwise, state that they cannot enter right now. The capacity is 100 at most. Subtract the people from the count and print the current number of people.

User Helospark
by
5.1k points