Question

In: Computer Science

Use python Only can use if statement and loop, that's professor's requirement I have no idea...

Use python

Only can use if statement and loop, that's professor's requirement

I have no idea how to do that without class

Building Entrance
Tracker
Due to Covid-19, we can allow
only 5 guests to our building at a
time. Our task is to write a
program that helps the entrance
staff to keep track of guest entries
to the building.
Feature 1 (40 points): Each guest
must sign in upon entry into the
building. If the number of guests
currently in the building is already
at the limit of 5 persons, inform
the guest that he/she cannot
enter. Otherwise, allow entrance
and record the name of the guest
to the system.
Feature 2 (40 points): Each guest
must sign out upon exiting the
building. At sign-out, the guest
enters his/her name. If the name
is not in the system inform the
guest that this name is not in the
building. Otherwise, ask the guest
to input how long (in minutes)
he/she spent in the building.
Remove the name of the guest
from the system, and record the
time spent.
Feature 3 (40 points): When
asked for a report, the system
should display the number of
people currently in the building
along with the names of those
people. It should also report the
average number of minutes our
guests spend in the building.
Feature 0 (30 points): When we
ask to exit the program, we
should be prompted with a
warning if there are still guests in
the building. Upon confirmation,
users can still quit the program.
Make sure to include minimum
3-4 comments in your source
code.
EXAMPLE RUN:
Building Entrance Management
=============================
1- Sign In
2- Sign Out
3- Report
0- Exit
Choice? 3
There are 0 person(s) in the building.
Building Entrance Management
=============================
1- Sign In
2- Sign Out
3- Report
0- Exit
Choice? 1
Name: Ali
Entrance allowed!
Building Entrance Management
=============================
1- Sign In
2- Sign Out
3- Report
0- Exit
Choice? 1
Name: Alice
Entrance allowed!
Building Entrance Management
=============================
1- Sign In
2- Sign Out
3- Report
0- Exit
Choice? 3
There are 2 person(s) in the building.
1 - Ali
2 - Alice
Building Entrance Management
=============================
1- Sign In
2- Sign Out
3- Report
0- Exit
Choice? 2
Name: John
This person is not in the building!
Building Entrance Management
=============================
1- Sign In
2- Sign Out
3- Report
0- Exit
Choice? 2
Name: Ali
Time Spent (in Minutes): 10
Ali exited the building.
Building Entrance Management
=============================
1- Sign In
2- Sign Out
3- Report
0- Exit
Choice? 3
There are 1 person(s) in the building.
1 - Alice
People spend on average 10.0 minutes.
Building Entrance Management
=============================
1- Sign In
2- Sign Out
3- Report
0- Exit
Choice? 1
Name: John
Entrance allowed!
Building Entrance Management
=============================
1- Sign In
2- Sign Out
3- Report
0- Exit
Choice? 1
Name: Mark
Entrance allowed!
Building Entrance Management
=============================
1- Sign In
2- Sign Out
3- Report
0- Exit
Choice? 1
Name: Melissa
Entrance allowed!
Building Entrance Management
=============================
1- Sign In
2- Sign Out
3- Report
0- Exit
Choice? 1
Name: Kai
Entrance allowed!
Building Entrance Management
=============================
1- Sign In
2- Sign Out
3- Report
0- Exit
Choice? 1
Name: Ryan
Cannot allow more than 5 people!
Building Entrance Management
=============================
1- Sign In
2- Sign Out
3- Report
0- Exit
Choice? 3
There are 5 person(s) in the building.
1 - John
2 - Alice
3 - Mark
4 - Melissa
5 - Kai
People spend on average 10.0 minutes.
Building Entrance Management
=============================
1- Sign In
2- Sign Out
3- Report
0- Exit
Choice? 2
Name: Alice
Time Spent (in Minutes):4
Alice exited the building.
Building Entrance Management
=============================
1- Sign In
2- Sign Out
3- Report
0- Exit
Choice? 3
There are 4 person(s) in the building.
1 - John
2 - Mark
3 - Melissa
4 - Kai
People spend on average 7.0 minutes.
Building Entrance Management
=============================
1- Sign In
2- Sign Out
3- Report
0- Exit
Choice? 2
Name: Mark
Time Spent (in Minutes):6
Mark exited the building.
Building Entrance Management
=============================
1- Sign In
2- Sign Out
3- Report
0- Exit
Choice? 3
There are 3 person(s) in the building.
1 - John
2 - Melissa
3 - Kai
People spend on average
6.666666666666667 minutes.
Building Entrance Management
=============================
1- Sign In
2- Sign Out
3- Report
0- Exit
Choice? 0
There are still 3 person(s) in the building
Are you sure you would like to exit the
program? (y/n) n
Building Entrance Management
=============================
1- Sign In
2- Sign Out
3- Report
0- Exit
Choice? 2
Name: Kai
Time Spent (in Minutes): 10
Kai exited the building.
Building Entrance Management
=============================
1- Sign In
2- Sign Out
3- Report
0- Exit
Choice? 3
There are 2 person(s) in the building.
1 - John
2 - Melissa
People spend on average 7.5 minutes.
Building Entrance Management
=============================
1- Sign In
2- Sign Out
3- Report
0- Exit
Choice? 0
There are still 2 person(s) in the building
Are you sure you would like to exit the
program? (y/n) y
good bye!

Solutions

Expert Solution

Here we have used a list to store name of people entering the building and time spent by them.

The complete code with appropriate comments is :

# list to contain the name of people in the building
ppl = []
# list to contain time soend by people leaving  the Building
times = []
# print menu until user decides to exit
while True:
    # print the menu
    print ('Building Entrance Management')
    print("=============================")
    print("1- Sign In")
    print("2- Sign Out")
    print("3- Report")
    print("0- Exit")
    # take input
    choice = int(input("Choice?"))  
    
    if choice == 1:
        name = input("Name: ")
        # if 5 ppl are already in building
        if len(ppl) >=5:
            print("Cannot allow more than 5 people!")
        else:
            print("Entrance allowed!")
            ppl.append(name)
    elif choice == 2:
        name = input('Name: ')
        time_spent = input("Time Spent (in Minutes)") 
        # if person is in building
        if name in ppl:
            print(name," exited the building.")
            # remove him from list of person in building
            ppl.remove(name)
            # add his time spend to list 
            times.append(time_spent)
        # if person name is not in those  inside building 
        else:
            print("This person is not in the building!")
    # report
    elif choice == 3:
        print("There are", len(ppl)," person(s) in the building.")
        for i in range(len(ppl)):
            print(i+1,"- ",ppl[i])
        if len(times)>0:
            sum = 0
            for i in times:
                sum+=i
            avg = sum/(len(times)+1)
            print("People spend on average", avg ,"minutes.")
    elif choice == 0:
        print("There are still", len(ppl), "person(s) in the building")
        conf =  input("Are you sure you would like to exit the program? (y/n)")
        if conf == 'y':
            break

Output:


Related Solutions

How would I get rid of punctuation that's in a file so that I am only...
How would I get rid of punctuation that's in a file so that I am only left with words after turning them into a list in Python. So if the file contained "and in the dream, I am flying.", how would I get a list that contained ['and', 'in', 'that', 'dream', 'I', 'am', 'flying'] not ['and', 'in', 'that', 'dream,', 'I', 'am', 'flying.']
it's the Heckscher–Ohlin Model, that's all the info I have. The answer can be general, thank...
it's the Heckscher–Ohlin Model, that's all the info I have. The answer can be general, thank you! Use the shoe and computer example from the lecture notes, with shoe production using labor intensively and computer production using capital intensively. Examine the long-run impacts following a natural disaster that decreases the foreign country's population on a) factor prices in the foreign country b) production in the foreign country what happens to the rentals on land and capital in the long run?
I have to use a sentinel while loop to complete the following task in a java...
I have to use a sentinel while loop to complete the following task in a java program, I want to see how this is executed so I can better understand how the sentinel while loop works. Thank you! Convert Lab 10 from a counter controlled WHILE loop to a sentinel WHILE loop. Do the following: Prompts the user to enter a grade or a -1 to quit. IF the user entered a -1 THEN Display a message that the User...
(using for loop, parameters, if, else condition only )Python: Write a program that prompts the user...
(using for loop, parameters, if, else condition only )Python: Write a program that prompts the user to enter a positive integer value, and compute the following sequence: • If the value is even, halve it. • If it's odd, multiply by 3 and add 1. • Repeat this process until the value is 1, printing out each value. • Then print out how many of these operations you performed. If the input value is less than 1, print a message...
Python Write a for loop with a range function and format output as currency Use an...
Python Write a for loop with a range function and format output as currency Use an input statement to ask the user for # of iterations using the prompt: #? [space after the ?] & assign to a variable Convert the variable to an integer Use a for loop and a range function to display all whole numbers from 1 to the user entered number Display the value of the item variable on screen in each iteration in the following...
IN PYTHON ( Use Fuctions and or with Loop if comfortable) Your friends just bought a...
IN PYTHON ( Use Fuctions and or with Loop if comfortable) Your friends just bought a new five room house and need your help to know how much it will cost to re-do the floors. Write a program that, given the dimensions of each of the five rooms and the desired type of flooring, outputs the cost of each room as well as the total cost. Hardwood costs $1.39/sqft, carpet costs $3.99/sqft, and tile costs $4.99/sqft. Input Validation: Your program...
what example can I use when explaining the four requirement s of a differnce of means...
what example can I use when explaining the four requirement s of a differnce of means test?
Using Python, use the following list (Temperature = [56.2,31.8,81.7,45.6,71.3,62.9,59.0,92.5,95.0,19.2,15.0]) to: - Create a loop to iterate...
Using Python, use the following list (Temperature = [56.2,31.8,81.7,45.6,71.3,62.9,59.0,92.5,95.0,19.2,15.0]) to: - Create a loop to iterate through each of the elements in the temperature list. - Convert each element of this list to a Celsius temperature and then, for each valid temperature in the list, print out both the original Fahrenheit temperature and the Celsius equivalent in this format: "32 degrees Fahrenheit is equivalent with 0 degrees Celsius."
Problem IN PYTHON ( Use Fuctions and or with Loop if comfortable) Your friends just bought...
Problem IN PYTHON ( Use Fuctions and or with Loop if comfortable) Your friends just bought a new five room house and need your help to know how much it will cost to re-do the floors. Write a program that, given the dimensions of each of the five rooms and the desired type of flooring, outputs the cost of each room as well as the total cost. Hardwood costs $1.39/sqft, carpet costs $3.99/sqft, and tile costs $4.99/sqft. Input Validation: Your...
Important: please use python. Using while loop, write python code to print the times table (from...
Important: please use python. Using while loop, write python code to print the times table (from 0 to 20, incremented by 2) for number 5. Add asterisks (****) so the output looks exactly as shown below.   Please send the code and the output of the program. ****************************************************************** This Program Shows Times Table for Number 5 (from 0 to 20) Incremented by 2 * ****************************************************************** 0 x 5 = 0 2 x 5 = 10 4 x 5 = 20 6...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT