In: Computer Science
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!
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: