Question

In: Computer Science

You have the following appointment slots booked during the day: 8am - 10am, 11am - 12pm,...

You have the following appointment slots booked during the day: 8am - 10am, 11am - 12pm, 1:30pm - 3pm, 2pm - 5pm. Write a program that takes as input a list of booked appointment slots, and returns slots when you are free. You solution should be generalized to work with any valid input. Assumptions: Your day starts at 8am and ends at 6pm. You can have overlapping booked appointments. Hints/suggestions: Use military time so 1:30pm is represented as 1330, for example. Use a tuple (800,1000) to represent time slot 8am - 10am. FYI: this is Python Programming Language

Solutions

Expert Solution

Program Code Screenshot:

Sample Output:

The screenshots are attached below for reference.

Please follow them for proper indentation and output.

Program code to copy:

l=[]
while True:
print("Enter slot or -1 to stop")
temp=list(map(int,input().split()))#read time slots as tuples as specified
if(temp[0]==-1):
break
l.append((temp[0],temp[1]))
res=[]
for i in range(1,len(l)):
if l[i][0]<l[i-1][1]:
continue
else:
if(l[i][0]>1200):
res.append(str(l[i][0]-1200)+"pm")#convert the times to 12 hr format
if l[i-1][1]>1200:
res.append(str(l[i-1][1]-1200)+"pm")
else:
res.append(str(l[i-1][1])+"am")
else:
res.append(str(l[i][0])+"am")
if l[i-1][1]>1200:
res.append(str(l[i-1][1]-1200)+"pm")
else:
res.append(str(l[i-1][1])+"am")

res.append("600pm")#append the final time

if(l[-1][1]>1200):
res.append(str(l[-1][1]-1200)+"pm")#check the difference between the final slot and final time
else:
res.append(str(l[-1][1])+"am")

for i in range(len(res)):
res[i]=res[i][:-4]+":"+res[i][-4:]


print("The available time slots are :") #print the slots available
for i in range(len(res)-1,-1,-2):
print(res[i]," to ",res[i-1])


Related Solutions

You are working as an accountant. One day Ali calls you to make an appointment for...
You are working as an accountant. One day Ali calls you to make an appointment for a meeting. At the meeting Ali is very excited to share great news. Ali and his new best friend Fatiha have decided to open a new restaurant offering halal food in COVID-19 safe booths. They do not know whether they should trade as: (1) a sole trader where Ali will be sole trader and hire Fatiha as a manager because she has less experience...
You have a dentist appointment for teeth filling. During your visit your regular doctor is not...
You have a dentist appointment for teeth filling. During your visit your regular doctor is not available but instead you are greeted by Dr. Sweeney Todd. Dr. Todd performs a tooth surgery on you but his skills in identifying which region to fill are not very accurate. He decides that he will fill the top right molar (TR) with probability 0.5, Top left molar with probability (TL) 0.6, and bottom left molar with probability (BL) 0.1. In addition, to the...
You are assessing Mr. Clements during his 4-week follow-up appointment after discharge from the hospital. You...
You are assessing Mr. Clements during his 4-week follow-up appointment after discharge from the hospital. You need to include a sexual health history as a routine part of the nursing history. Give examples of nonjudgmental questions you will ask to determine his sexual function.
Suppose you have invested the following sums on the last day of each year in a...
Suppose you have invested the following sums on the last day of each year in a mutual fund with front-end loads of 4% and management fees of 0.4%. The fund earned 11% per year. How much will you have at the end of year 10? Year                Cash Flow     0                       $1600     1                       $2500     2                       $3000
January 1st 2034, you have chosen to step down from day to day operations and have...
January 1st 2034, you have chosen to step down from day to day operations and have hired a former Vice President of Starbucks, George, to run Cool Beans now that the number of locations has expanded dramatically.  There are currently 72 locations that span from Miami, FL to Charleston, SC, and your coffee beans are on store shelves of Publix, Winn Dixie, and Piggly Wiggly.  You have identified an acquisition target, Crazy Mocha of Pittsburgh.  The owner is willing to sell the chain...
You flip a coin, if it is heads you will have a good day and if...
You flip a coin, if it is heads you will have a good day and if it is tails you will have a bad day. There are 30 days in total. (a) What is the expectation and variance of the number of times you will have a good day throughout this 30 day stretch? (b) What is the probability that every day will be bad for all of the 30 days?
You are a supervisor at Martin’s Office Supply. During the course of your day you notice...
You are a supervisor at Martin’s Office Supply. During the course of your day you notice that some of your employees are spending a good deal of time on the Internet for personal use. You observe one of your employees posting to his Facebook page and another employee conducting a job search onwww.monster.com   You realize that the personal Internet use interferes with productivity. Read the web articles (provided below) then write a memo to advise your staff that in the next...
if you have desire to have a 500,000 nest egg one day, how much will you...
if you have desire to have a 500,000 nest egg one day, how much will you need to contribute to an retirement account on a monthly basis assuming you have 30 years to save and expect an average rate or return of 5.5%?
You have just started an internship with Frode Laursen and you have spent your first day...
You have just started an internship with Frode Laursen and you have spent your first day together with a Key Account Manager (KAM), who handles transactions with three different customer segments (A, B and C). He proudly tells you that his focus is on serving the A customers since they yield the highest contribution margin per transaction. Then come the B customers, and if there is time left, he also serves the C customers. Upfront, his argument sounds logical, but...
Suppose that you receive on average, 10 text messages during a day. What is the probability...
Suppose that you receive on average, 10 text messages during a day. What is the probability that you receive 25 messages today? Also, that you receive 15 messages during 2 days? 16. On average, there are 3 car accidents between 8 am-11 am at point A. What is the probability that there will be 5 accidents during 9 am-10 am at this place? Also, that there will be 8 accidents during 8 am-12 noon? 17. On average, there are 3...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT