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, 21.06.2019 22:00
Your task this week is to write a very simple spam classifier in python. it will classify messages as either spam (unwanted) or ham (wanted). the program will have a set of spam_words, words that are known to appear in spam messages. that set is included in the template file spam.pypreview the document. you will also define a spam threshold which reflects the allowed percentage of spam words in the message. you'll compute a 'spam indicator', which is the ratio of spam words to the total number of unique words in the message. if the spam indicator exceeds the spam threshold, the message is classified as spam. otherwise it is classified as ham. we'll assume that the spam threshold is a constant and has a value of 0.10. your program will prompt the user for a message and then will print the corresponding spam indicator with two decimal digits and the corresponding classification (spam or ham). the program will be case insensitive. the spam words are detected whether they are in lower case or upper case or mixed case. each word, spam or not, is counted once (even if it appears multiple times in the message.) the program will remove punctuation from the message before identifying the words and computing the spam indicator. for example '! ' must be identified as the spam word 'now'.
Answers: 3
question
Computers and Technology, 22.06.2019 09:30
Is a string of code written to hurt others by damaging or destroying
Answers: 1
question
Computers and Technology, 22.06.2019 18:00
Write a method named addall that could be placed inside the hashintset class. this method accepts another hashintset as a parameter and adds all elements from that set into the current set, if they are not already present. for example, if a set s1 contains [1, 2, 3] and another set s2 contains [1, 7, 3, 9], the call of s1.addall(s2); would change s1 to store [1, 2, 3, 7, 9] in some order. you are allowed to call methods on your set and/or the other set. do not modify the set passed in. this method should run in o(n) time where n is the number of elements in the parameter set passed in.
Answers: 2
question
Computers and Technology, 22.06.2019 18:40
Mariah was working on a multimedia presentation that included both video and audio files. the file was huge, and she wanted to send it to her coworker in another office. she needed to reduce the size of the file so that it could be transmitted faster. the utility she used to do this was
Answers: 2
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, 09.04.2020 04:35
question
Mathematics, 09.04.2020 04:36
question
Mathematics, 09.04.2020 04:36
Questions on the website: 13722363