Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

We will incrementally build a simple class (a Clock class). Hints Look at the function divmod in the Python documentation. What does it do? Your

image text in transcribedimage text in transcribedimage text in transcribed

We will incrementally build a simple class (a Clock class). Hints Look at the function divmod in the Python documentation. What does it do? Your Tasks Overall, we are going to design a class, a Clock class, which does some simple operations. 1. First, let's define the class called Clock. a. Open a new file and define a class Clock. In the beginning it won't have any methods in it. In fact, to ensure this you can define the class, and then have the only line in the class suite be the keyword pass, telling the interpreter there is nothing in the class. b. Save the file and then load the class c. In the interpreter make an instance of your new class 2. Once that works, we have a skeleton (bare bones, no functionality) class. We need to add to the class. The most important method to get in the class is the constructor (the _init_ method). The constructor defines the variables that are stored in each instance that is created. a. Delete the pass statement. We want to add to our class! b. Create the constructor to take 4 parameters: the first is self (as is true for any method) and the remaining three are: hours, minutes, seconds. Each of the last three should be a named parameter and have reasonable defaults. c. In the constructor, assign the 3 parameters to three variables in the instance being created. In the instance, again call those variables hours, minutes and seconds. d. Add a doc string to your constructor (a string immediately after the header using created using the triple-quote syntax) explaining what each parameter after the first stands for and what type is expected for each. e. Save and load the file. Try out the new class in the interpreter. Make some new instances (with and without default parameters) and print the variables in those instances 3. Write a method called Get_time() to get the hours, minutes and seconds of a clock. The method takes one parameter self and return the hours, minutes and seconds of the clock. 4. Write a method called update _lock0 to update the hours, minutes and seconds in a clock when the seconds value increases by some value( generally the increased value is 1). a. The input parameter should be self and a value to be added to the seconds b. The hours, minutes, seconds in a clock should be updated. For example, if the current time is 3:30:59pm (hours =3, minutes =30, seconds =59 ) and the seconds increases by 1 , the time should become (3:31:00pm) (hours =3, minutes =31,seconds =0). You need to use divmod to determine whether the hours, minutes, seconds will be updated or not. c. Remember that the sum of seconds cannot exceed 60 , in which case there is a carry over to the minutes values. Same for minutes, it cannot exceed 60 and carries over to hours. For hours, the summed values cannot exceed 12 . If hours is exceeded, we ignore it. 5. Write a new method called clock_display. The method takes one parameter self and will display the a. In your program, you need to import my module called Lab_clock.py, which was provided as the attachment. You can directly call the function display_clock() in the your clock_display method. b. Please test the Lab_clock.py to understand how it works. 6. Create a clock called New_york_clock and make it run as a real clock to show the time. (Please watch the attached video and understand how the clock should work). a. Please initialize the clock using the following time initial_time=time.time ( initial_time=time.localtime(initial_time) You can only use the above sentences once. Please learn time.time() and time.localtime() in time module. Use initial_time[3], initial_time[4], initial_time[5] to get the hours, minutes, and seconds. b. Write a loop to update the clock and display the clock every one 1 second. Please use time.sleep(1) to pause for one second and then update you clock by calling update_clock 0 method with seconds value increased by 1 and then call the clock_display to display the time. You are required to use two Python packages: numpy and matplotlib. Please try import numpy import matplotlib If they are not installed yet, please follow the instructions below to install them 1. Test if you pip can work using "py m pip

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Systems A 360-degree Approach

Authors: Jawwad ShamsiMuhammad Khojaye

1st Edition

0429531575, 9780429531576

More Books

Students also viewed these Databases questions

Question

8. Praise the trainees for their success in learning the task.

Answered: 1 week ago