Open main menu

CDOT Wiki β

Changes

Rchan sandbox

260 bytes added, 23:31, 2 November 2019
Part 2 - Pure Function and Modifiers
</source>
:7. The result is not correct! So we have to modify and update the change_time() function so that it can handle positive and negative value correctly. The following steps are necessary:
::(a) We must first add code to check on the '''second''' attribute of the time object to make sure that it is not less than zero. If it is, we must borrow one from the '''minute''' attribute and add 60 to the '''second''' attribute. We have to repeat this checking until the '''second''' attribute is no long less than zero. <source lang="python"> while time.second < 0: time.minute -= 1 time.second += 60</source>::(b) We then have to add code to check on the '''minute''' attribute. If it is less than zero, we must borrow 1 from the 'hour' attribute and add 60 to the '''minute''' attribute. We have to repeat this checking until the '''minute''' attribute is no long less than zero.<source lang="python"> while time.minute < 0: time.hour -= 1 time.minute += 60</source
:8. After updating the change_time() function with the above additional code, save the file and test it again in a Python interactive shell by importing the new version of the function.<source lang='bash'>
[rchan@centos7 lab7]$ python3
1,760
edits