subject
Computers and Technology, 27.07.2021 19:30 toro63

Create a class named Clock to represent a time in hours and minutes. (I am using the name Clock because there is an existing module named time and I want to avoid conflicts.) Store this class in a file named clock. py. As hinted in the previous paragraph, objects of this class have two attributes that must be named hour and minute. The hour ranges from 0 to 23, and the minute from 0 to 59. Your class will implement the following methods: __init__(self, hour, minute) The constructor creates a new Clock with the given hour and minute. Your constructor must ensure that, no matter what numbers are given, the hour is from 0 to 23 and the minute from 0 to 59. Thus, if someone tries this: import clock t1 = clock. Clock(19, 12) t2 = clock. Clock(-5, 74) .The first object represents the time 7:12 p. m. The second object has bad input, so do whatever you feel is reasonable to create a valid time. My code creates a Clock representing 5:14 a. m. from the bad input. (Hint: I used abs and % to force the numbers into the range I wanted.) __str__(self) This method returns a string representing the time in 24-hour European notation; so this code: import clock t = clock. Clock(17, 8) t2 = clock. Clock(3, 45) print(t) print(t2) Produces this output: 1708 0345 add(self, other) This method returns a new Clock object that is the result of adding the two times. For example: import clock t1 = clock. Clock(2, 37) # 2:37 a. m. t2 = clock. Clock(5, 29) # 5:29 a. m. t3 = t1.add(t2) print(t3) # prints 0806. subtract(self, other) This method returns a new Clock object that is the result of subtracting the two times. For example: import clock t1 = clock. Clock(18, 20) t2 = clock. Clock(3, 45) t3 = t1.subtract(t2) print(t3) # prints 1435 Your method should always subtract the smaller time from the larger time, so if I had written t3 = t2.subtract(t1) I would have gotten the same result. Hint: you can use abs() to make your life easier. The next two functions must be declared before the class declaration. from_european(s) This function takes a string that has a European time in it as its argument and returns a new Clock object with the corresponding time. You might use it as follows: import clock t = clock. from_european('1732') print(t. hour) # output will be 17 print(t. minute) # output will be 32 print(t) # output will be 1732 from_am_pm(s) This function takes a string that has a time in AM/PM format it as its argument and returns a new Clock object with the corresponding time. You might use it as follows: import clock t = clock. from_am_pm('3:46 p. m.') print(t. hour) # output will be 15 print(t. minute) # output will be 46 print(t) # output will be 1546 Your function must accept the AM or PM in upper or lower case, with or without periods, but you may presume there will be at least one space after the digits. (Just look for the A or P, don’t worry about the period or M.)
Use this file as your starting point.
This function accepts the AM or PM in upper or lower case, with or without periods, presuming there will be at least one space after the digits. "class Clock: def __init__(self, hour, minute): """The constructor creates a new Clock with the given hour and minute. It ensures that, no matter what numbers are given, the hour is from 0 and 23 and the minute from 0 to 59. """ def __str__(self): """Return a string representing the time in 24-hour European notation """ def total_minutes(self): """ This is a utility function that takes a Clock object and returns the number of minutes past midnight that it represents. (I am providing this code for you.) """ return self. hour * 60 + self. minute def add(self, other): """Return a new Clock object that is the result of adding self to other. """ def subtract(self, other): """Return a new Clock object that is the result of subtracting the smaller time from the larger time. "

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 15:10
David is in week 3 of his current ashford course and has a paper due by monday night at midnight. he has finished everything but the concluding paragraph. as he boots up his computer to work on it, he sees a flash across the screen and then the screen goes black. he begins to panic as he tries desperately to turn the laptop back on. david should have saved his work on what kind of portable device?
Answers: 2
question
Computers and Technology, 22.06.2019 19:20
Terri needs to insert a cover page into her document. where should she go to access the commands to do so? o insert tab, objects group o insert tab, illustrations group o insert tab, pages group o insert tab, media group submit
Answers: 1
question
Computers and Technology, 22.06.2019 23:30
The next button in the review section shows the next available comment. next slide with no comment. previous comment. edited comment.
Answers: 1
question
Computers and Technology, 24.06.2019 07:50
Write a defining table and then a program that determines if you can sleep in or not. your program should get all its input from your computer’s clock. on all weekdays (monday through friday) that are not holidays, your program should output “get up! ” on all other days (weekends and holidays), your program should output “sleep in.” the three holidays that your program must check for are january 1 (new year’s day), july 4 (u.s. independence day), and december 25 (christmas). you don’t need to include other holidays in your program because most other holidays do not occur on a fixed day each year.
Answers: 1
You know the right answer?
Create a class named Clock to represent a time in hours and minutes. (I am using the name Clock beca...
Questions
question
Social Studies, 16.02.2021 09:00
question
Mathematics, 16.02.2021 09:00
question
History, 16.02.2021 09:00