Question

Python #Imagine you're writing a program to check if a person is #available at a certain...

Python

#Imagine you're writing a program to check if a person is
#available at a certain time.
#
#To do this, you want to write a function called
#check_availability. check_availability will have two
#parameters: a list of instances of the Meeting class, and
#proposed_time, a particular date and time.
#
#check_availability should return True (meaning the person
#is available) if there are no instances of Meeting that
#conflict with the proposed_time. In other words, it should
#return False if proposed_time is between the start_time and
#end_time for any meeting in the list of meetings.
#
#The Meeting class is defined below. It has two attributes:
#start_time and end_time. start_time is an instance of the
#datetime class showing when the meeting starts, and
#end_time is an instance of the datetime class indicating
#when the meeting ends.
#
#Hint: Instances of the datetime have at least six
#attributes: year, month, day, hour, minute, and second.
#
#Hint 2: Comparison operators work with instances of the
#datetime class. time_1 < time_2 will be True if time_1 is
#earlier than time_2, and False otherwise.
#
#You should not assume that the list is sorted.

#Here is our definition of the Meeting class:
from datetime import datetime
class Meeting:
def __init__(self, start_time, end_time):
self.start_time = start_time
self.end_time = end_time

#Write your function here!


#Below are some lines of code that will test your function.
#You can change the value of the variable(s) to test your
#function with different inputs.
#
#If your function works correctly, this will originally
#print: True, then False
meetings = [Meeting(datetime(2018, 8, 1, 9, 0, 0), datetime(2018, 8, 1, 11, 0, 0)),
Meeting(datetime(2018, 8, 1, 15, 0, 0), datetime(2018, 8, 1, 16, 0, 0)),
Meeting(datetime(2018, 8, 2, 9, 0, 0), datetime(2018, 8, 2, 10, 0, 0))]
print(check_availability(meetings, datetime(2018, 8, 1, 12, 0, 0)))
print(check_availability(meetings, datetime(2018, 8, 1, 10, 0, 0)))

Homework Answers

Answer #1

I have commented the code

#Imagine you're writing a program to check if a person is
#available at a certain time.
#
#To do this, you want to write a function called
#check_availability. check_availability will have two
#parameters: a list of instances of the Meeting class, and
#proposed_time, a particular date and time.
#
#check_availability should return True (meaning the person
#is available) if there are no instances of Meeting that
#conflict with the proposed_time. In other words, it should
#return False if proposed_time is between the start_time and
#end_time for any meeting in the list of meetings.
#
#The Meeting class is defined below. It has two attributes:
#start_time and end_time. start_time is an instance of the
#datetime class showing when the meeting starts, and
#end_time is an instance of the datetime class indicating
#when the meeting ends.
#
#Hint: Instances of the datetime have at least six
#attributes: year, month, day, hour, minute, and second.
#
#Hint 2: Comparison operators work with instances of the
#datetime class. time_1 < time_2 will be True if time_1 is
#earlier than time_2, and False otherwise.
#
#You should not assume that the list is sorted.

#Here is our definition of the Meeting class:
from datetime import datetime
class Meeting:
    def __init__(self, start_time, end_time):
        self.start_time = start_time
        self.end_time = end_time

#Write your function here!
def check_availability(meetings,meetingTime):
    ans = True # variable to store ans
    for meeting in meetings: #iterate through the list
#if the proposed meeting falls in between the current meeting return false
        if meetingTime >= meeting.start_time and meetingTime <=meeting.end_time: 
            ans = False
    return ans


#Below are some lines of code that will test your function.
#You can change the value of the variable(s) to test your
#function with different inputs.
#
#If your function works correctly, this will originally
#print: True, then False
meetings = [Meeting(datetime(2018, 8, 1, 9, 0, 0), datetime(2018, 8, 1, 11, 0, 0)),
Meeting(datetime(2018, 8, 1, 15, 0, 0), datetime(2018, 8, 1, 16, 0, 0)),
Meeting(datetime(2018, 8, 2, 9, 0, 0), datetime(2018, 8, 2, 10, 0, 0))]
print(check_availability(meetings, datetime(2018, 8, 1, 12, 0, 0)))
print(check_availability(meetings, datetime(2018, 8, 1, 10, 0, 0)))

Output

True
False
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Python Problem 1 Create a function, biggest_ip_sum, outside of the ServerClass class, that: 1. Takes two...
Python Problem 1 Create a function, biggest_ip_sum, outside of the ServerClass class, that: 1. Takes two ServerClass objects 2. Sums the octets of the IP together (example 127.0.0.1 = 127+0+0+1 = 128) 3. Returns the larger number Example: server_one = ServerClass("127.0.0.1") server_two = ServerClass("192.168.0.1") result = biggest_ip_sum(server_one, server_two) print(result) In the example above, result will be 361. _________________________________ Problem 1 Here is the code to start with class ServerClass: """ Server class for representing and manipulating servers. """ def __init__(self,...
Using python 3.5 or later, write the following program. A kidnapper kidnaps Baron Barton and writes...
Using python 3.5 or later, write the following program. A kidnapper kidnaps Baron Barton and writes a ransom note. It is not wrriten by hand to avoid having his hand writing being recognized, so the kid napper uses a magazine to create a ransom note. We need to find out, given the ransom note string and magazine string, is it possible to given ransom note. The kidnapper can use individual characters of words. Here is how your program should work...
Python Blackjack Game Here are some special cases to consider. If the Dealer goes over 21,...
Python Blackjack Game Here are some special cases to consider. If the Dealer goes over 21, all players who are still standing win. But the players that are not standing have already lost. If the Dealer does not go over 21 but stands on say 19 points then all players having points greater than 19 win. All players having points less than 19 lose. All players having points equal to 19 tie. The program should stop asking to hit if...
Program will allow anywhere between 1 and 6 players (inclusive). Here is what your output will...
Program will allow anywhere between 1 and 6 players (inclusive). Here is what your output will look like: Enter number of players: 2 Player 1: 7S 5D - 12 points Player 2: 4H JC - 14 points Dealer: 10D Player 1, do you want to hit? [y / n]: y Player 1: 7S 5D 8H - 20 points Player 1, do you want to hit? [y / n]: n Player 2, do you want to hit? [y / n]: y...
My assignment is listed below. I already have the code complete, but I cannot figure out...
My assignment is listed below. I already have the code complete, but I cannot figure out how to complete this portion: You must create a makefile to compile and build your program. I can't figure out if I need to create a makefile, and if I do, what commands do I use for that? Create a  ContactInfo class that contains the following member variables: name age phoneNumber The ContactInfo class should have a default constructor that sets name = "", phoneNumber...
USING PYTHON do all the he problems using while loop , continue and break 1-This problem...
USING PYTHON do all the he problems using while loop , continue and break 1-This problem provides practice using a while True loop.write a function named twoWords that gets and returns two words from a user. The first word is of a specified length, and the second word begins with a specified letter.The function twoWords takes two parameters: an integer, length, that is the length of the first word and a character, firstLetter, that is the first letter of the...
/* This program should check if the given integer number is prime. Reminder, an integer number...
/* This program should check if the given integer number is prime. Reminder, an integer number greater than 1 is prime if it divisible only by itself and by 1. In other words a prime number divided by any other natural number (besides 1 and itself) will have a non-zero remainder. Your task: Write a method called checkPrime(n) that will take an integer greater than 1 as an input, and return true if that integer is prime; otherwise, it should...
write a python program that include a function named activity_selection() and take in two arguments, first...
write a python program that include a function named activity_selection() and take in two arguments, first one would be the number of tasks and the second argument would be a list of activities. Each activity would have an activity number, start time and finish time. Example activity_selection input and output: activity_selection (11, [[1, 1, 4 ], [2, 3, 5], [3, 0, 6], [4, 5, 7], [5, 3, 9], [6, 5, 9],[7, 6, 10], [ 8, 8, 11], [ 9, 8,...
/* Write a function that looks for a particular person in their respective linked list The...
/* Write a function that looks for a particular person in their respective linked list The only place you need to write code is the "find" method in the linked list class */ #include <bits/stdc++.h> using namespace std; string ltrim(const string &); string rtrim(const string &); #define BUFFLEN 10 /* Each "person" is defined by their name, zipcode, and their pet's name. Persons are hashed by their zipcode. */ //---------------------------------------------------------------------------- /* function declarations ------------------------*/ int computeKey(int); void add_to_buffer(string,int,string); void find_in_buffer(int);...
write a code in python Write the following functions below based on their comments. Note Pass...
write a code in python Write the following functions below based on their comments. Note Pass is a key word you can use to have a function the does not do anything. You are only allowed to use what was discussed in the lectures, labs and assignments, and there is no need to import any libraries. #!/usr/bin/python3 #(1 Mark) This function will take in a string of digits and check to see if all the digits in the string are...