Which stores and manipulates times on a 24 hour clock.

Assignment Help Python Programming
Reference no: EM13987404

Complete the class Time, which stores and manipulates times on a 24 hour clock. As specified below, write the required methods, including those needed for overloading operators. Exceptions messages should include the class and method names, and identify the error (including the value of all relevant arguments). Hint see the type_as_str function in the goody.py module.

  1. The class is initialized with three int values (the hour first, the minute second, the second third; all with default values of 0). If any parameter is not an int, or not in the correct range (the hour must be between 0 and 23 inclusive, the minute and second must be between 0 and 59 inclusive) raise an AssertionError with an appropriate string describing the problem/values. When initialized, the Time class should create exactly three self variables named hour, minute, and second (with these exact names and no others self variables).
  2. Write the __getitem__ method to allow Time class objects to be indexed by either (a) an int with value 1 or 2 or 3, or (b) any length tuple containing any combinations of just these three values: e.g., (1,3). If the index is not one of these types or values, raise an IndexError exception with an appropriate string describing the problem/values. If the argument is 1, returns the hour; if the argument is 2, return the minute, and if the argument is 3, return the second. If the argument is a tuple, return a tuple with hour or minute or second substituted for each value in the tuple. So if t = Time(5,15,20) then t[1] returns 5 and t[2,3] returns (15,20). Note that calling t[1] will pass 1 as its argument; calling t[1,2] will pass the tuple (1,2) as its argument.
  3. Write methods that return (a) the standard repr function of a Time, and (b) a str function of a Time: str for a Time shows the time in the standard 12 hour clock format: str(Time(13,10,5)) returns '1:10:05pm'; str(Time(5,6,3)) returns '5:06:03am'; str(Time(0,0,0)) returns '12:00:00am'. It is critical to write the str method correctly, because I used it in the batch self-check file for testing the correctness of other methods.
  4. Write a method that interprets midnight as False and any other time as True.
  5. Write a method that interprets the length of a Time as the number of seconds that have elapsed from midnight to the that time. So len(Time(0,0,0)) returns 0 and len(Time(23,59,59)) returns 86,399; there are 86,400 seconds in a day: midnight to midnight.
  6. Overload the == operator to allow comparing two Time objects for equality (if a time object is compared against an object from any other class, it should return False). Note that if you define == correctly, Python willbeabletocompute!=byusing ==.
  7. Overload the < operator to allow comparing two Time objects. The left Time is less-than the right one if it comes earlier in the day than the right one. Also allow the right operand to be an int: in this case, return whether the length (an int, see above) of the Time is less-than the right int. If the right operand is any other type, raise a TypeError exception with an appropriate string describing the problem/values. Note that if you define < correctly, Python will be able to compute Time > Time and int > Time by using <.
  8. Overload the + operator to allow adding a Time object and an int, producing a new Time object as a result (and not mutating the Time object + was called on). If the other operand is not an int, raise a TypeError

exception with an appropriate string describing the problem/values. Both Time + int and int + Time should be allowed and have the same meaning. Hint: write code that adds one second to a Time; then iterate over this code the int number of time.

9. Write the __call__ method to allow an object from this class to be callable with three int arguments: update the hour of the object to be the first argument, and the minute of the object to be the second argument,andthesecondoftheobjecttobethethirdargument.ReturnNone. Ifanyparameterisnotlegal (see how the class is initialized), raise an AssertionError with an appropriate string describing the problem/values.

Reference no: EM13987404

Questions Cloud

Create a ride share simulator assignment : Create a ride share simulator assignment. In this particular function, I am trying to create a list of the drivers in a Driver Class that are currently listed as idle. Since they are idle, I can then match them up with an awaiting rider. The assignme..
What distance from the unstrained position is the speed : The block is pulled away from the spring's unstrained position by a distance x0 = 0.050 m and released from rest. The period of the subsequent periodic motion of the block is 0.64 s. At what distance from the unstrained position is the speed of the b..
Is doe guilty of the possession charge : Is Doe guilty of the possession charge? Fully explain the basis of your position. What facts not provided in this case would you want to know in order to determine guilt
What distance from the unstrained position is the speed : The block is pulled away from the spring's unstrained position by a distance x0 = 0.050 m and released from rest. The period of the subsequent periodic motion of the block is 0.64 s. At what distance from the unstrained position is the speed of the b..
Which stores and manipulates times on a 24 hour clock. : Complete the class Time, which stores and manipulates times on a 24 hour clock. As specified below, write the required methods, including those needed for overloading operators. Exceptions messages should include the class and method names, and ident..
What is the price of the bill what is its bond equivalent : What is the price of the bill? (Use 360 days a year. Do not round intermediate calculations. Round your answer to 2 decimal places.) What is its bond equivalent yield? (Use 365 days a year. Do not round intermediate calculations. Round your answer to..
How will the following new quantities relate to quanities : Now, replace the block with one half the mass and set the block into motion again by pulling the block a distance 10cm from equilibrium and releasing. How will the following new quantities relate to the quanities with the original block? (If it wi..
What is the messimer''s final tax that should be paid : The Messimers sent her $4,000 for help with expenses and estimate that she made $4,500 more that she used for her support. Their itemized deductions are $48,350 before any reduction.
The program should use a boolean= valued function : Write a program that accepts a word as input and determines wehther or not it has three consecutive letters in the alphabet. The program should use a Boolean= valued function named isTripleConsecutive that accepts an entire word as input.

Reviews

Write a Review

Python Programming Questions & Answers

  Programmer does not have to use the def statement

Unlike Z+-, the programmer does not have to use the DEF statement to create a variable. Instead, the programmer can simply use the variable. The first use of the variable creates it and initializes it to 0.

  What prompted the authors to try and address

What is the question that this study is trying to answer and what prompted the authors to try and address this question?

  Recursive sorts are easier to write in functional style

Recursive sorts are easier to write in functional style than others. Two recursive sorts are  Quicksort and Mergesort. Write functional versions of (a) Quicksort; (b) Mergesort in an  imperative language of your choice (e.g., C, Ada, C++, Python), us..

  The interest rate per period

The interest rate per period. For example, if your loan's interest is 6.5% per year, and you are paying monthly, this would be 6.5%/12. If you are paying every two weeks, r would be 6.5%/26, because there are 26 two-week periods in a year.

  We would like to implement the lexical order

We would like to implement the lexical order for lists. For simplicity, we only consider lists of numbers, where , >= have their usual meaning.

  Enter an integer for the base of the power

This assignment requires one file containing a main function and a recursive function named power.

  Turn the turtle image into a .gif picture

How can you turn the turtle image into a .gif picture when using the built-in turtle for Python? If that's impossible how do you remove the line when you move the turtle around?

  Do a python project and get it running using app engine

Do a python project and get it running using App engine. Something very basic and simple

  In this assignment you will write a program that does

in this assignment you will write a program that does simple packet routing. your program will take three command-line

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Output the starting position and length

X Strings: Input a string. Output the starting position and length of the first occurrence of the longest substring of capital Xs in that string. The first letter is in position 1.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd