Changes

Jump to: navigation, search

Rchan sandbox

807 bytes added, 15:33, 2 November 2019
no edit summary
:5 If you pay a little bit attention on the outputs, you should notice that the sum_times() function did not carry 60 minutes over to hour. It also will not carry 60 seconds over to minute.
:6 To fix that problem, perform the following:
::(a) Edit the file '''lab7a.py''' and modify the function sum_times(). Add code to check the values of the time object's three attributes. If the value of the minute attribute is more than 60, carry it over to the hour until it is less than 60. Do the same for the value of the second attribute.::(b) The follow indicates where you should perform the carry over in the sum_times() function in '''lab7a.py''':<source lang="python">......def sum_times(t1, t2): """Add two time objests and return the sum.""" sum = Time(0,0,0) sum.hour = t1.hour + t2.hour sum.minute = t1.minute + t2.minute sum.second = t1.second + t2.second #[ insert python code here to check for minute and second #[ attribute here, and carry over when necessary #[ return sum......</source>::(c) Save the file.::(d) Test run your script '''lab7a1.py''' again and make sure that it produces the output that match the following exactly:<source lang="bash">[rchan@centos7 lab7]$ python3 lab7a1.py08:00:00 + 00:50:00 --> 08:50:0008:55:00 + 00:50:00 --> 09:45:0009:50:00 + 00:50:00 --> 10:40:00</source>
:7. Download the checking script and check your work. Enter the following commands from the bash shell.<source lang="bash">
cd ~/ops435/lab7/
1,760
edits

Navigation menu