Study Guides (380,000)
CA (150,000)
UW (6,000)
CS (400)
CS116 (10)

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

Computer Science
Course Code
Study Guide

This preview shows pages 1-3. to view the full 11 pages of the document.
CS 116 final (PYTHON) – Natasha Park
CS Final Exam Review
= is the assignment operator “becomes”
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
- 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
- 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
To convert something (usually an argument of the function which changes depending on
what you put in) into a string, use str()  use int() to convert a string into an integer so “3”
becomes 3
To determine the type of something, use type()  so type(5) yields <type ‘int’>
To find the length of a string, use len(“ “) so len(blah blah) would yield 9 (counts spaces)
To find maximum or minimum, use max(a, b, c) and min(a, b, c)
We use “if” (vs. “cond” in Scheme)
Make sure you have two “=”, so: if x == 3: (don’t forget the colon)
!= is shorthand for not equal
Use “elif” for chained conditional statements, so
- “if age < 3” is one condition, then “elif age < 18” really means >=3, <18
Use “else” last

Only pages 1-3 are available for preview. Some parts have been intentionally blurred.

CS 116 final (PYTHON) – Natasha Park
Math module
Design Recipe
## function_name: int Bool float -> None
## Purpose:
## Effects:
## Tests:
Tests in Python

Only pages 1-3 are available for preview. Some parts have been intentionally blurred.

CS 116 final (PYTHON) – Natasha Park
User input
User_input = raw_input() where user_input is a name, raw_input is a function
The program stops, and nothing happens until the user types at the keyboard
When user hits return, a string containing all the characters before return is produced by
The value produced by raw_input is always a string
You're Reading a Preview

Unlock to view full version