Assignment 11 Wiki - AustinSoup/CS101L GitHub Wiki
Clock
We’ll use our skills to create a clock class that can keep track of hours, minutes and seconds. The you should be able to create an instance with values for hour, minutes and seconds. You’ll want to make a new class with a ini method. You’ll want to set the attributes for hour, minute, and second in the init.
We’ll use our skills to create a clock class that can keep track of hours, minutes and seconds. The you should be able to create an instance with values for hour, minutes and seconds. You’ll want to make a new class with a ini method. You’ll want to set the attributes for hour, minute, and second in the init.
Adding to our clock example tick method. Create a tick() method for the clock. When tick gets called, it should increment the # of seconds. If the number of seconds is 60 or over, then then we increment the number of minutes, and set seconds to 0. If the number of minutes gets set to 60 or over, then we increment the hours.
Changing the clock type We’ll want to add a new default argument to the init method which will be the clock type. The parameter will default to 0, which means a 24 hour clock. The other option 1 would indicate a 12 hour clock. The internal clock will remain unchanged, but our output when printed will change depending on what type of clock is represented. The 12 hour clock will only show hours 1 - 12, with am or pm. 00:00:20 would be 12:00:20 am. While 12:00:20 would be 12:00:20 pm
Clock Program Using the clock class we’ve built create a program to ask a user for hours, minutes and seconds, and create a clock based on that. Then write a loop that calls tick() once a second and then sleeps for a second. Use time module to sleep. Try the example below for using time
The program asks the users to enter the current hour. After the user inputs a number , its the user for the current minute, and also current second. Then the program will show what the user inputted. Then the program will continuously output the time and will keep refreshing to show the time of the clock.