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 20:00
Need asap assignment directions: think of an organization (business, religious institution, volunteer organization, sports team) with which you have been involved. imagine outfitting it with an it infrastructure. prepare a plan for what you would do to support outfitting it. draw a map of a network connecting all the individuals, give them pcs and printers, and lay out the design as best you can. the purpose is to begin working with these concepts, not to build a perfect network.
Answers: 2
question
Computers and Technology, 22.06.2019 21:00
So im doing this school challenge and the teachers said whats the average text a student gets a day so i need to get about 20 in a day but dont know how can you guys 2163371293
Answers: 2
question
Computers and Technology, 24.06.2019 13:30
Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. the program should output the average high, average low, and the highest and lowest temper- atures for the year. your program must consist of the following functions: a. function getdata: this function reads and stores data in the two- dimensional array. b. function averagehigh: this function calculates and returns the average high temperature for the year. c. function averagelow: this function calculates and returns the aver- age low temperature for the year. d. function indexhightemp: this function returns the index of the highest high temperature in the array. e. function indexlowtemp: this function retur
Answers: 3
question
Computers and Technology, 24.06.2019 18:30
What is the local portion of the e-mail address below? [email protected] a.) @ b.) biz c.) gumchewer d.) twrigley
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
Mathematics, 14.11.2020 22:40
question
English, 14.11.2020 22:50
question
Mathematics, 14.11.2020 22:50
question
Mathematics, 14.11.2020 22:50
question
Geography, 14.11.2020 22:50
question
Medicine, 14.11.2020 22:50
Questions on the website: 13722360