CS 110 Lecture 7: CS 110 Lesson 7 notes
Document Summary
Only good for constants needed in multiple functions, such as pi or e. Defined by the surrounding block: def main(): x = 2 for j in [1,2,3]: x = j print x. This will print 3, because the x in the for loop block overshadows the original x. Can only be used in the function it was defined in. Some list of values that need to be tallied up in some way: example: sum = 0 ----- sum is the accumulator for j in [1,2,3,4]: sum = sum+j. *the booleans must be capitalized! print (5 == 5) This will print true print (5 == 6) There are 6 boolean operators: == : tests equality. != : tests inequality: < : less than, >= : greater than or equal, <= : less than or equal. Logical operators and : requires both boolean operators to yield true for the and operator to return true.