Question

In: Computer Science

PYTHON You need to control the number of people who can be in an oyster bar...

PYTHON

  1. 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.

Solutions

Expert Solution

Solution:

#To hold total occupants count
total_occupants = 0

#Will get executed till the total ocuupants reach 100
while(total_occupants < 100):
  
#Getting group size entering or leaving
group_size = input("Enter the size of group arrive / depart : ")

#converting string to integer
group_size = int(group_size)

#adding the group size to the count of total occupants
total_occupants += group_size

#checking whether the total occupants count reached maximum
if(total_occupants >= 100):
#printing bar is full and exiting from loop
print("Bar is full.")
break;

#displaying total occupants currently there in bar
print("Total number of occupants at this time : ", total_occupants)

Program screenshot:

Output screenshot:


Related Solutions

Write a code snippet for the following:   You need to control the maximum number of people...
Write a code snippet for the following:   You need to control the maximum number of people who can be in a   restaurant at any given time. A group cannot enter the restaurant if they   would make the number of people exceed 100 occupants. Use random numbers   between 1 and 20 to simulate groups arriving to the restaurant. After each   random number, display the size of the group trying to enter and the number   of current occupants. As soon as the...
6) One thousand people compete in an oyster-eating contest. Their scores (number of oysters eaten) are...
6) One thousand people compete in an oyster-eating contest. Their scores (number of oysters eaten) are normally distributed with a mean of 51 and standard deviation of 11. What is the probability that a given individual will eat less than 29 or more than 72? Select one: ( ) a. 98% ( ) b. 5% ( ) c. 13% ( ) d. 2% ( ) e. 47%
According to a regional Bar​ Association, approximately 60​% of the people who take the bar exam...
According to a regional Bar​ Association, approximately 60​% of the people who take the bar exam to practice law in the region pass the exam. Find the approximate probability that at least 63​% of 400 randomly sampled people taking the bar exam will pass. Answer the questions below. The sample proportion is 0.63. What is the population​ proportion?
According to a regional Bar​ Association, approximately 60​% of the people who take the bar exam...
According to a regional Bar​ Association, approximately 60​% of the people who take the bar exam to practice law in the region pass the exam. Find the approximate probability that at least 61​% of 500 randomly sampled people taking the bar exam will pass. Answer the questions below. The sample proportion is 0.610 What is the population​ proportion?
Problem . Determine the number of people who can be sustainably supported by a watershed under...
Problem . Determine the number of people who can be sustainably supported by a watershed under the following conditions: (a) watershed area = 207.2 km2 ; (b) annual rainfall rate = 114.3 cm/year; (c) annual evaporation rate = 50.8 cm/year; (d) water resource development = 75%; (e) raw water reservoir volume to store 50% net annual yield or provide half of a year’s water supply, whichever is higher = 49.205 BL; and (f) water consumption rate = 568 Lpcd.
In Python, your program will read in a number (no need to prompt the user), and...
In Python, your program will read in a number (no need to prompt the user), and then reads in that number of lines from the terminal. Then the program should print an array of strings formatted in a nice regular box. So if the user inputs this: 5 Grim visaged war has smooth’d his wrinkled front And now, instead of mounting barded steeds To fright the souls of fearful adversaries He capers nimbly in a lady’s chamber To the lascivious...
The first random number generator comes from Python itself. To use it you need to import...
The first random number generator comes from Python itself. To use it you need to import the Python package. Then call the random() method. See below. import random print (random.random()) It is important to know that a random number generator really is random. If so, it should have uniform distribution between 0 and 1. Test the random number generators in Python for uniformity.
2) You work for GrubHub delivering takeout to people who ask for delivery. You need to...
2) You work for GrubHub delivering takeout to people who ask for delivery. You need to purchase a vehicle and are trying to decide between two choices. The first is a gasoline car that currently sells for $27,500, gets 20 miles to the gallon, has a resale value of $8,500 in 10 years and has maintenance costs of $750 per year. The alternative is an electric car that costs $35,000, has a resale value of $15,000 in 10 years, and...
Can you please write this in python thank you. Consider 'x' being a number chosen by...
Can you please write this in python thank you. Consider 'x' being a number chosen by a user. Using python conditional statements, write a code that: prints "x is a multiple of 3 and 5" if x is dividable by both numbers 3 and 5 prints "x is a multiple of 7 or 11" if x is dividable be either numbers 7 or 11.
You can use up to three levels of security and protection to control who can access...
You can use up to three levels of security and protection to control who can access and change your Excel data. Please describe two of the three levels and how you access each of them.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT