CS116 Study Guide - Final Guide: Binary Search Algorithm, For Loop, Key Type Stamp

294 views11 pages

Document Summary

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. Printing on one line: 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. Len( a\nb\nc\n ) 6 \n counts as one character. Basic functions: for division, 5/3 yields 1 (quotient), while 5%3 yields 2 (remainder) for int numbers only. Comparisons: we use if (vs. cond in scheme, make sure you have two = , so: if x == 3: (don"t forget the colon, use elif for chained conditional statements, so. If age < 3 is one condition, then elif age < 18 really means >=3, <18: use else last. Creating formatted strings: : the string you are building uses % inside to show where a value should be inserted in new string.