Lecture 1 Next Lecture

Lecture 1, Mon 04/03

Orientation to the course

The syllabus is here: https://ucsb-cs8-s18.github.io/info/syllabus/

Some of the code from lecture

import math

def factorialTable(limit):
    for i in range(limit):
        print(i,math.factorial(i))

import turtle

fred = turtle.Turtle("turtle")
fred.color("green")

fred.forward(200)


def drawSquare(side):
  for i in range(4): 
    fred.forward(side)
    fred.right(90)
for i in range(5):
	drawSquare(i * 20)

Abstractions and Algorithms

(a review of part of the syllabus)

Abstractions and notation: three, index.

An index takes in as input a topic, and gives us back a page number.

A Point-of-Sale bar code scanner at a store checkout maps a barcode, to info about the item (description and price).

A FUNCTION in general, takes in an input (or a set of inputs) and gives us back a value.

In math, for example,

f(x) = x2

Learning Something New

Python REPL (Read Eval Print Loop)

Also called the Python Shell Prompt

login as: pconrad
pconrad@csil-01.cs.ucsb.edu's password:
Last login: Mon Aug  7 15:29:19 2017 from 98.188.150.204
-bash-4.3$
-bash-4.3$ python3
Python 3.4.3 (default, Aug  9 2016, 15:36:17)
[GCC 5.3.1 20160406 (Red Hat 5.3.1-6)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 2 + 3
5
>>> 2 + 7 *4
30
>>> 2 ** 3
8
>>> 2 ** 3 ** 2
512
>>> 2 * 3 * 4
24
>>> (2 * 3) * 4
24
>>> 2 * (3 * 4)
24
>>> (2 ** 3) ** 2
64
>>> 2 ** (3 ** 2)
512
>>>

Note that ** is right associative, not left associative.

The textbook and the homework

IDLE and Python

For loops

This:

>>> for x in schools:
	print(x)

	
A
B
C
D
>>>

Is a short hand for this:

>>> x = schools[0]
>>> print(x)
A
>>> x = schools[1]
>>> print(x)
B
>>> x = schools[2]
>>> print(x)
C
>>> x = schools[3]
>>> print(x)
D
>>>