====== Computer Lab 03, functions, errors and exceptions ====== ===== practical work ===== We use the code implemented last week, from [[http://openbookproject.net/thinkcs/python/english3e/|Wentworth2012]] and make it more flexible by encapsulating the core functionality in functions. **2.14.5** Create a function ''compute_final_amount'' that will have ''P,r,n,t'' as the input parameters. Comment the function appropriately. Make the code robust against dividing by zero runtime problem: - Use if-condition to catch the case where the denominator is zero, print an error message (using 'print') and return from the function. - Use if-condition to catch the case where the denominator is zero and raise an exception. - Handle this exception completely with a "try-except" block, i. e., no if-condition needed. ===== Weekly homework 03 ===== **time difference** variant of 2.14.7 and 2.14.8. Implement a function ''compute_time_diff(h1,m1,h2,m2)'' that returns two values - hours, minutes - time difference between t2-t1, where the time is expressed in hours and minutes. Expect 24 hours notation. Required file name: ''03_weekly_hw.py''. Usage: >>> h,m = compute_time_diff(13,20,15,10) >>> print(h,m) 1 50 ===== homework ===== Solve homework [[courses:be5b33prg:homework:regular:01_right_triangle|01 - Right triangle]] and submit it via Upload system in time! Check the deadline in Upload system. * Read chapters 6,7,8,9 from [[http://openbookproject.net/thinkcs/python/english3e/|Wentworth2012]]. This material is for the next two lectures/labs.