Changes

Jump to: navigation, search

Rchan sandbox

54 bytes added, 17:15, 2 November 2019
Part 2 - Pure Function and Modifiers
== Part 2 - Pure Function and Modifiers ==
In Part 1, the sum_times() function did will not make any change to any of the two time objects. It is called a pure function. In this part, we are going to create a function which changes the value (the three attributes) of a time object based on the integer value passes to the function. We call such type of function a modifier. The function we are going to add is called change_time(time, seconds), : where time is the time object the function is going to modify, and seconds is the given number of seconds to be added the function will add to the time object.
:1. Make a copy of lab7a.py and name it as lab7b.py in the ~/ops435/lab7 directory
>>> format_time(time1)
'10:20:00'
>>> seconds = -1800>>> change_time(time1,-1800seconds)
>>> format_time(time1)
'10:20:-1800'
</source>:7. It is not, so correct! So we have to modify and update the change_time() function so that the change_time() function can handle positive and negative value correctly. After the function change_time() has been updated, test it again in a Python interactive shell with import<source lang='bash'>
[rchan@centos7 wiki_labs]$ python3
Python 3.4.9 (default, Aug 14 2018, 21:28:57)
1,760
edits

Navigation menu