CS116 Study Guide - Final Guide: Binary Search Algorithm, For Loop, Empty String

902 views10 pages

Document Summary

Assignment statements don"t produce a value, they only have an effect. Print does not produce a value, but has an effect. Numbers are either an int or a float (float if inexact; so 3 is an int, but 3. 0 and 3. 1 are floats) Do not compare 2 floating point numbers for exact equality (so use check within) You can use int, float, or (union int float) in contracts as needed. We know how to use print statements to put information on one line. To use 1 print statement to put info over multiple lines, use \n one line\n another \nanother . Len( a\nb\nc\n ) 6 \n counts as one character. For division, 5/3 yields 1 (quotient), while 5%3 yields 2 (remainder) for int numbers only. Float just produces the entire number, so 1/3 = 0. 3333. Use * for multiplication, and ** for exponents. To take the absolute value, use abs() so abs(-3. 8) yields 3. 8.