Top Banner
Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING CSC111: Introduction to CS through Programming R. Jordan Crouser Assistant Professor of Computer Science Smith College
44

Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

Mar 23, 2022

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

Lecture 3:

INTRO TO PYTHON & PAIR PROGRAMMINGCSC111: Introduction to CS through ProgrammingR. Jordan CrouserAssistant Professor of Computer ScienceSmith College

Page 2: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

Announcements

• Note Taker: paid position available- Requirements: on work study, 1.5hr week-What you’ll do: take clear, concise notes for this course and

deliver them to the Office of Disability Services- If interested: email Lisa Roberge in ODS at [email protected]

(subject: Note Taker for CSC111-01 / R. Jordan Crouser)

Page 3: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

Overview of the week

üCrash course in computersüA little historyü4 key componentsüQuick hardware demoüBoolean logic

• Introduction to Python

• Life skill #1: pair programming

• Lab: Getting Started with Python

• User Input

Page 4: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

Recap

What do you remember

from Monday’s class?

Page 5: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

Recap: the good news

• “High level” programming languages like Python mean we don’t have to write in “low level” binary

• Instead, we write statements like:

print(“hello”)

Page 6: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING
Page 7: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

What do you know?

Page 8: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

multi-paradigm interpreted language with dynamic typing

and automatic memory management

Page 9: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

multi-paradigm interpreted language with dynamic typing

and automatic memory management

object-oriented functional imperative declarative

Page 10: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

multi-paradigm interpreted language with dynamic typing

and automatic memory management

Page 11: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

Quick digression

COMPILER INTERPRETERWhat it

takes in:What it returns:Relative

speed:Memory

usage:Work is

done:Reports

errors:Example

language:

Page 12: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

Quick digression

COMPILER INTERPRETERWhat it

takes in:an

entire programa single line of code

(or a single instruction)What it returns:

intermediate object code (e.g. classes) <nothing>

Relative speed: faster slower

Memory usage:

uses more memory(↑ objects take space ↑)

uses less memory(no intermediate objects)

Work is done: just once every time the

code is executedReports

errors:after checking

the entire programafter each

instruction is run

Page 13: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

multi-paradigm interpreted language with dynamic typing

and automatic memory management

more about this a bit later

Page 14: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

Core concept 1: variables

• In CS, a variable is a place to store a piece of data

• In Python, variables are:- declared by giving them a name- assigned using the equals sign

• Example:

x = 3declaring a variable x

assigning the value 3 to x

Page 15: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

Core concept 2: numeric values

• Two kinds of numbers in CS:- integers (“whole numbers”)- floats (“decimals” or “floating point numbers”)

• In Python, the kind of number is implied by whether or not the number contains a decimal point

• Example:

x = 3x = 3.0

Page 16: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

Basic operations on numbers

• Addition: +• Subtraction: -

• Multiplication: *

• Division: /

• Exponentiation: ** (power)

• Modular arithmetic: % (modulo)

Page 17: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

Core concept 3: strings

• In CS, a sequence of characters that isn’t a number is called a string

• In Python, a string is declared using quotation marks• Strings can contain letters, numbers, spaces, and special

characters• Example:

x = “Jordan”x = “Stoddard G2”

Page 18: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

Math on strings?!

• Let’s say we have:

x = “Jordan”

• If we ask Python for:

2*xwhat will happen?

Page 19: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

print(): a very useful function

• A function is a procedure / routine that takes in some input and does something with it (just like in math)

• In Python, the print() function takes in a value and outputs the value to the console

• This seems silly now, but will come in handy in lab when you write/run your first program inside a file

Page 20: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

Quick check in

a = 1b = 2.7c = “Smithies”

Page 21: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

Overview of the week

üCrash course in computersüA little historyü4 key componentsüQuick hardware demoüBoolean logic

üIntroduction to Python

• Life skill #1: pair programming

• Lab: Getting Started with Python

• User Input

Page 22: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

The programming process

D. Thiebaut, Computer Science, Smith College

The Programming Process

Page 23: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

The programming process (idealized)

D. Thiebaut, Computer Science, Smith College

• Analyze the Problem

• Determine Specifications

• Create a Design

• Implement

• Test & Debug

• Maintain

The Programming Process

Page 24: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

The programming process (idealized)

D. Thiebaut, Computer Science, Smith College

• Analyze the Problem

• Determine Specifications

• Create a Design

• Implement

• Test & Debug

• Maintain

The Programming Process

Page 25: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

The programming process (idealized)

D. Thiebaut, Computer Science, Smith College

The Programming Process

• Analyze the Problem

• Determine Specifications

• Create a Design

• Implement

• Test & Debug

• Maintain

Page 26: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

The programming process (idealized)

D. Thiebaut, Computer Science, Smith College

The Programming Process

• Analyze the Problem

• Determine Specifications

• Create a Design

• Implement

• Test & Debug

• Maintain

Page 27: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

The programming process (idealized)

D. Thiebaut, Computer Science, Smith College

The Programming Process

• Analyze the Problem

• Determine Specifications

• Create a Design

• Implement

• Test & Debug

• Maintain

Page 28: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

The programming process (more realistic)

D. Thiebaut, Computer Science, Smith College

The Programming Process

• Analyze the Problem

• Determine Specifications

• Create a Design

• Implement

• Test & Debug

• Maintain

iterate many times

Refine the

Page 29: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

Getting started

D. Thiebaut, Computer Science, Smith College

The Programming Process

Page 30: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

“S4”: start small | slow | simple

D. Thiebaut, Computer Science, Smith College

The Programming Process

Page 31: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

Next: address the constraints

D. Thiebaut, Computer Science, Smith College

The Programming Process

Page 32: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

Add additional features

D. Thiebaut, Computer Science, Smith College

The Programming Process

Page 33: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

Finally: hit target

D. Thiebaut, Computer Science, Smith College

The Programming Process

Page 34: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

Discussion

So what does this

look like in practice?

Page 35: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

A problematic (but common) model

Page 36: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

A better model: “pair programming”two

people

onemachine

Page 37: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

Two complimentary roles

drivernavigator

Page 38: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

A common analogydriver

navigator

Page 39: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

Navigator vs. driver: different focus

“how”“why”

“what”

Page 40: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

A professional perspective (& some tips)

Page 41: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

Reality check

What makes this approach so hard?

Page 42: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING
Page 43: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

Overview of the week

üCrash course in computersüA little historyü4 key componentsüQuick hardware demoüBoolean logic

üIntroduction to Python

üLife skill #1: pair programming

• Lab: Getting Started with Python

• User Input

Page 44: Lecture 3: INTRO TO PYTHON & PAIR PROGRAMMING

Your first taste of pair programming!