CSC148H1 Lecture Notes - Lecture 5: Init, Docstring, Triple Parentheses
katrinasavvy and 38715 others unlocked
1
CSC148H1 Full Course Notes
Verified Note
1 document
Document Summary
References: all code seen in the pictures can be found on the csc148 website: http://www. teach. cs. toronto. edu/~csc148h/winter/ Assignment 1 and lab 2 exercises have been posted. The __lt__ method doesn"t work under all conditions: doesn"t work if one number is negative. Write a functional if statement: already know dysfunctional if statement -> code from last lecture that didn"t work. Functional if statement: if else If condition is true, expression 1 is returned. If condition isn"t true, expression 2 is returned: n1 * d2 < n2 * d1 if d1 * d2 > 0 else n1 * d2 > n2* d1. This can be written in python as: Class rational doesn"t exist as a type in the header, so it needs to written as a string. No quotes around rational because it has already been defined. It has been mentioned several times throughout the code that the denominator shouldn"t be 0: known as a precondition .