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, 23.06.2019 14:30
Select the correct answer. which step can possibly increase the severity of an incident? a. separating sensitive data from non-sensitive data b. immediately spreading the news about the incident response plan c. installing new hard disks d. increasing access controls
Answers: 2
question
Computers and Technology, 23.06.2019 21:20
In microsoft word, when you highlight existing text you want to replace, you're in              a.  advanced mode.    b.  automatic mode.    c.  basic mode.    d.  typeover mode
Answers: 1
question
Computers and Technology, 24.06.2019 11:20
Colby works as a shipping clerk for a major package delivery service. some of his daily tasks include tracking shipments and entering orders. which aspect of the information technology cluster would he most likely be trained in? a.networkingb.databasesc.hardwared.software
Answers: 2
question
Computers and Technology, 24.06.2019 14:40
Create a function (prob3_6) that will do the following: input a positive scalar integer x. if x is odd, multiply it by 3 and add 1. if the given x is even, divide it by 2. repeat this rule on the new value until you get 1, if ever. your program will output how many operations it had to perform to get to 1 and the largest number along the way. for example, start with the number 3: because 3 is odd, we multiply by 3 and add 1 giving us 10. 10 is even so we divide it by 2, giving us 5. 5 is odd so we multiply by 3 and add one, giving us 16. we divide 16 (even) by two giving 8. we divide 8 (even) by two giving 4. we divide 4 (even) by two giving 2. we divide 2 (even) by 2 to give us 1. once we have one, we stop. this example took seven operations to get to one. the largest number we had along the way was 16. every value of n that anyone has ever checked eventually leads to 1, but it is an open mathematical problem (known as the collatz conjectureopens in new tab) whether every value of n eventually leads to 1. your program should include a while loop and an if-statement.
Answers: 3
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
Questions on the website: 13722362