Question

Could someone help me out with the following python question? Preferably using the "return a <=...

Could someone help me out with the following python question? Preferably using the "return a <= b < c" method instead of a standard if else statement. I would appreciate a step by step explanation if possible. Thank you!

Write a class called Appointment with methods as described below:

__init__() method

Define an __init__() method with four parameters:

  • self

  • name, a string indicating the name of the appointment (for example, "Sales brunch").

  • start, a tuple consisting of two integers representing the start time of the appointment. The first integer represents an hour in 24-hour time; the second integer represents a number of minutes. For example, the tuple (10, 30) would represent 10:30 am.

  • end, a tuple similar to start representing the end time of the appointment.

The __init__() method should create attributes name, start, and end, and use them to store the information from the parameters.

overlaps() method

Define an overlaps() method with two parameters, self and other, where other is another Appointment object.

This method should return True if self and other overlap and False if they do not. Be sure to return a boolean value rather than a string.

Note that two appointments overlap if

  • the start time of one appointment occurs between the start and end times of the other appointment (including if the start times are equal), OR

  • the end time of one appointment occurs between the start and end times of the other appointment (including if the end times are equal)

For this assignment, if the start time of one appointment is equal to the end time of the other appointment, the two appointments are not considered to overlap.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code

class Appointment:
#init method
def __init__(self,name,start,end):
self.__name=name;
self.__start=start;
self.__end=end
#method overlaps
def overlaps(self,other):
#if other Appointment's start time is in between this Appointment' start time and end time then both Appointment overlaps
if other.__start[0]>=self.__start[0] and other.__start[0]<self.__end[0]:
return True
#if thos Appointment's start time is in between other Appointment' start time and end time then both Appointment overlaps
if self.__start[0]>=other.__start[0] and self.__start[0]<other.__end[0]:
return True

#if other Appointment's end time is in between this Appointment' start time and end time then both Appointment overlaps
if other.__end[0]>self.__start[0] and other.__end[0]<self.__end[0]:
return True

#if this Appointment's end time is in between other Appointment' start time and end time then both Appointment overlaps
if self.__end[0]>other.__start[0] and self.__end[0]<other.__end[0]:
return True

#if other Appointment's start time Hour is same as this Appointment's end time Hour but its minutes is before this Appointment's end time minutes both Appointment overlaps
if other.__start[0]==self.__end[0]:
if other.__start[1]<self.__end[1]:
return True
#if This Appointment's start time Hour is same as Other Appointment's end time Hour but its minutes is before Other Appointment's end time minutes both Appointment overlaps
if self.__start[0]==other.__end[0]:
if self.__start[1]<other.__end[1]:
return True
return False

ap1=Appointment("Test1",(14,20),(15,30))
ap2=Appointment("Test2",(13,20),(14,30))

if ap1.overlaps(ap2):
print("Yes overlaps")
else:
print("No overlaps")

output

C. Command Prompt D:\Chegg\Python>py AppointmentClass.py Yes overlaps D:\Chegg\Python).

code snaps for indent

5. 7 8 AppointmentClass.py class Appointment: #init method def __init__(self, name, start, end): self._name=name; self. startAppointmentClass.py D. Chegg Python Atom File Edit View Selection Find Packages Help AppointmentClass.py 11 return True 12 #i

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
Could someone help me out with the following python question? Preferably using the "return a <=...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • pls help me with it. you just need to answer the question in Appointment.Java, There is...

    pls help me with it. you just need to answer the question in Appointment.Java, There is only 1 question u need to answer! Appointment.Java package option1.stage3; import option1.stage1.Doctor; import option1.stage1.Patient; import option1.stage2.TimeSlot; public class Appointment { private Doctor doctor; private Patient patient; private TimeSlot timeSlot; public Doctor getDoctor() { return doctor; } public void setDoctor(Doctor doctor) { this.doctor = doctor; } public Patient getPatient() { return patient; } public void setPatient(Patient patient) { this.patient = patient; } public TimeSlot getTimeSlot()...

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • Write the code in python programming Language String Statistics: Write a program that reads a string...

    Write the code in python programming Language String Statistics: Write a program that reads a string from the user and displays the following information about the string: (a) the length of the string, (b) a histogram detailing the number of occurrences of each vowel in the string (details provided below), (c) the number of times the first character of the string occurs throughout the entire string, (d) the number of times the last character of the string occurs throughout the...

  • Could someone please help me write this in Python? If time allows, it you could include...

    Could someone please help me write this in Python? If time allows, it you could include comments for your logic that would be of great help. This problem involves writing a program to analyze historical win-loss data for a single season of Division I NCAA women's basketball teams and compute from this the win ratio for each team as well as the conference(s) with the highest average win ratio. Background Whether it's football, basketball, lacrosse, or any other number of...

  • please help me with this python code thank you 1. Write a Student class that stores...

    please help me with this python code thank you 1. Write a Student class that stores information for a Rutgers student. The class should include the following instance variables: (10 points) o id, an integer identifier for the student o lastName, a string for the student&#39;s last name o credits, an integer representing the number of course-credits the student has earned o courseLoad, an integer representing the current number of credits in progress Write the following methods for your Student...

  • Hello I'm having a bit of trouble with this assignment. Any help would be appreciated! Overview...

    Hello I'm having a bit of trouble with this assignment. Any help would be appreciated! Overview You must implement a Java class which simulates a Student object. These Student objects will represent grade records for students. Variable Details  name : private String : represents the Student’s name  sid: private String : represents the Student’s ID number  quizzes: private double[] : an array whose size is equal to NUM_QUIZZES. Each element will be used to store one of...

  • %%%%Python Question%%% Work from the template acrostic.py, which you can find on the ELMS page for...

    %%%%Python Question%%% Work from the template acrostic.py, which you can find on the ELMS page for this assignment. • In the Generator class, write an __init__() method with two parameters: self and the path to a text file containing one word per line. This method should read the words from the file, strip off leading and trailing whitespace, and store them in a dictionary where each key is a lower-case letter and each corresponding value is a list of words...

  • python program A line segment in one dimension is defined by an ordered pair of coordinates...

    python program A line segment in one dimension is defined by an ordered pair of coordinates representing the left and right boundaries of the segment. Write a class Segment that implements the interface below, which includes testing whether a point is in a segment, and whether two segments overlap. Note that the constructor should raise an appropriate exception if it receives invalid input (left end is on the right of the right end). • __init__(): constructor that takes one or...

  • 11q Language is python need help 1) What is the output of the following code? Refer...

    11q Language is python need help 1) What is the output of the following code? Refer to the class defined here. Example: File 1: asset.py import asset class Asset: brains = asset.Asset( "Brains" ) strength = asset. Asset( "Strength" ) steel = asset.Asset( "Steel" ) wheelbarrow = asset. Asset( "Wheelbarrow" ) cloak = asset.Asset( "Cloak" ) def _init__( self, name): self.mName = name return def getName( self ): return self.mName al = strength + steel a2 = cloak + wheelbarrow...

  • Each question needs a screenshot of the result and the code. insert appropriate amount of comments...

    Each question needs a screenshot of the result and the code. insert appropriate amount of comments in the code. Exercise-1: Plant class. Define a class Plant that satisfies the spec below. Hints A. For this problem, provide an implementation for the Plant spec below, and test it using the example calls provided B. Although the constructor is described in the spec (and called) using the name Plant), the internal name for a class's constructor is_init__(). (There are two underscores before...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT