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...

  • 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...

  • 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...

  • Could someone help me out. I am not sure what I should be doing. Seeing it...

    Could someone help me out. I am not sure what I should be doing. Seeing it worked out will allow me to understand what I should be doing and then I can complete it on my own. Usando 2. Complete the Dog Class: a. Using the UML Class diagram to the right declare the instance variables. A text version is available: UML Class Diagram Text Version b. Create a constructor that incorporates the type, breed, and name variables (do not...

  • PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please...

    PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please so I can understand LinkedList ADT: class myLinkedList:     def __init__(self):         self.__head = None         self.__tail = None         self.__size = 0     def insert(self, i, data):         if self.isEmpty():             self.__head = listNode(data)             self.__tail = self.__head         elif i <= 0:             self.__head = listNode(data, self.__head)         elif i >= self.__size:             self.__tail.setNext(listNode(data))             self.__tail = self.__tail.getNext()         else:             current = self.__getIthNode(i - 1)             current.setNext(listNode(data,...

  • Write method createTeams() that Has no parameters Has return type void Instantiate the member variable of...

    Write method createTeams() that Has no parameters Has return type void Instantiate the member variable of type ArrayList<Team> Instantiates two instances of class Team one for TeamOne one for TeamTwo set names for each team as appropriate add each instance to the ArrayList<Team> member variable Instantiate the member variable of class Scanner passing “System.in” as the argument to the constructor Using System.out.println() static method, prompt the user for the human player’s name Instantiate an instance of class String set equal...

  • This is python coding recursive function question. Could anyone help me figuring out these not using...

    This is python coding recursive function question. Could anyone help me figuring out these not using built-in function? Thanks. Write a recursive function factorial(n) that returns the value of n!=1⋅2⋅3⋅⋯⋅n. 2. Write a recursive function reverse(text) that returns the reverse of the string named text. 3. Write a recursive function countUpper(s) that returns the number of uppercase letters in the string s. 4. Write a recursive function equal(list1, list2) that returns a Boolean value indicating whether the two lists are...

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
ADVERTISEMENT