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 have been invited to speak to a group of parents during the Family Day of...
You have been invited to speak to a group of parents during the Family Day of Cemerlang High School on the following topic: Social media has become increasingly popular amongst teenagers. What risks do sharing personal information on social media websites have and how can we combat them? Write the speech that you will be making to the parents. Provide two (2) main risks that sharing personal information on social media have and two (2) ways we can combat them....
You have been invited to speak to a group of parents during the Family Day of...
You have been invited to speak to a group of parents during the Family Day of Cemerlang High School on the following topic: Social media has become increasingly popular amongst teenagers. What risks do sharing personal information on social media websites have and how can we combat them? Write the speech that you will be making to the parents. Provide two (2) main risks that sharing personal information on social media have and two (2) ways we can combat them....
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...
In your day to day travels, select two individuals with whom you have a casual acquaintance....
In your day to day travels, select two individuals with whom you have a casual acquaintance. This might be a clerk at your bank or someone who works on your campus. Do not use students for this journal assignment. Offer genuine praise to these two individuals. Notice their reactions; their posture; their eye contact, etc. How do you think these reactions would differ if you had offered insincere or false praise to these two individuals? What might you say in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT