Computers and Technology
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. "

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 08:00, seaotter7140
Michael has written an e-mail to his employees that describes a new product special that will be introduced to the customers next week. by taking time to make sure the e-mail is well written, logical, and organized, michael has made sure his message has the characteristics of a) effective communicationb) ineffective communicationc) barriers to communicationd) workplace communication
Answers: 2
image
Computers and Technology, 23.06.2019 12:00, deflox74
What does the level 1 topic in a word outline become in powerpoint? a. first-level bullet item b. slide title c. third-level bullet item d. second-level bullet item
Answers: 1
image
Computers and Technology, 23.06.2019 13:30, Gearyjames8
Anetwork security application that prevents access between a private and trusted network and other untrusted networks
Answers: 1
image
Computers and Technology, 23.06.2019 14:30, officialrogerfp3gf2s
Select the correct answer. a company wants to use online methods to target more customers. it decides to conduct a market research by collecting the data of a few customers with their consent. they want to track data of the sites that their customers frequently visit. which software can the company? a. spyware b. bots c. adware d. trojan horse e. rootkits
Answers: 1
Do you know the correct answer?
Create a class named Clock to represent a time in hours and minutes. (I am using the name Clock beca...

Questions in other subjects: