programming with multimedia objects cs 177 lukasz (luke) ziarek basics course mechanics expectations...

70
Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Upload: brandon-green

Post on 26-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Programming with Multimedia ObjectsCS 177

Lukasz (Luke) Ziarek

BASICS

Course Mechanics

Expectations

1

Page 2: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Curriculum SurveyYou are asked to participate in a survey about

the core curriculum for the College of Sciences

https://purdue.qualtrics.com/SE/?SID=SV_3f2sMjxvGiPOCJ6

Page 3: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Goals for CS177Teach fundamentals of programming

Python

Show the scientific and interdisciplinary nature of computer science

Demonstrate the breadth of the field of computer science

Page 4: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Class MeetsLecture: Wed, Fri 4:30 ─ 5:20pm

Labs: many!

Recitation sessions: many!

TAs: check course website

Email: [email protected]

Web page: http://wiki.cs.purdue.edu/177/

4

Page 5: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Office HoursLuke Ziarek

W 12:00pm – 2:00pm F 1:00pm – 4:00pm HAAS 142

Dr. Martino M 12:00pm – 1:00pm T 10:00am -12:00pm

TAs Will be posted on class website

Additional hours will be scheduled closer to midterms and finals

Page 6: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

SCI 210Teaming Requirement

Given online via blackboard moduleFirst 6 weeks of the semester

2 Team Projects

Team Labs

Page 7: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Text Book

John Zelle

Python Programming: An Introduction to Computer

Science(SECOND EDITION)

Franklin, Beedle & Associates Inc.

7

We will use other material from the web including some the book’s website

Page 8: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Python Wiki BookWe will also make use of a Wiki Book (online

book)Link provided on course websiteVery concise referenceAdditional examples and exercises (practice)

http://en.wikibooks.org/wiki/Python_Programming

Page 9: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

PiazzaOnline Forum Software

Link, Registration Information, and Tutorial provided on class website

Post Questions on PiazzaFaster turn around timeUse your classmates as a resource

Registration:Use your Purdue Login ID Example: lziarek [email protected]

Page 10: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Piazza PoliciesDo not post answers on Piazza

This will be considered cheating

Make your questions as general as possibleAvoid posting large amounts of code

Use Tags#lab1 #project1 #prelab1

If you are note sure use the #private tag or emailOnly instructors and TAs can see (we will make it

public)

Page 11: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Grading5 Projects 25%

Weekly Lab 25%

2 midterm exams 25%

Final exam 20%

Class Participation 5%

Class will be graded on a curve

Borderline cases are a judgment call

11

Page 12: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

ProjectsDue in class at the beginning of course

Hand in will be electronic (similar to labs)

Late policy: Up to 24h: –20% Up to 48h: –50% More than 48h late: no credit

You may discuss the projects (Piazza), but you must do it separately Two projects will be team projects

Cheating cases sent to Dean of Students office

12

Page 13: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

ExamsNo extra materials

No cell phones, calculators, PDAs, etc

Cheating referred to Dean of Students Office

Week 6 and Week 11 exact times TBA

13

Page 14: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Labs and PreLabsStarting with Lab 2 we will offer a PreLab

Available on the course wikiNOT gradedWill contain a review and practice code to help you

study/prepare for Lab

PreLabs should take about an hour (or less)You can bring the PreLab to the lab Covers material in previous week

Will be made available on Friday of the week prior

Page 15: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

PoliciesPlease read and familiarize yourself with:

http://spaf.cerias.purdue.edu/cpolicy.htmlLink provided on course website

You must “sign” or accept the CS policies via the computer science portalMore details on the course website

Page 16: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

SoftwareJES – Robot Labs

Python Development Environment

IDLE - PythonVanilla Python

Note: JES will be introduced in your first robot lab

Page 17: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

iClickerWill be used for in class quizzes (attendance)

Page 18: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Class Structure (weekly)2 Lectures

Concepts

1 RecitationReview, Libraries, Interactive Coding, additional

background

1 Pre LabReview / Practice

1 LabRealizing concepts in code

Page 19: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Class StructureFirst 6 Weeks

Boot Camp for PythonLearn the Core Python Language

Rest of the classAdditional CS concepts

AlgorithmsData StructuresComplexity / Recursion / Others

Final ProjectBring everything together (Biology Application)

Page 20: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

What is computer science?

20

Page 21: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

What is computer science?

The study of process or computation expressed as algorithms.

“Computers are to computer science what telescopes are to astronomy.” – E. Dijkstra

21

Page 22: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

AlgorithmsAlgorithms are the main focus

Algorithms formally describe computational processes

Programs embody algorithms

Note: An algorithm is independent of how a program implements it

22

Page 23: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Algorithm Example1. Remove book from bag

2. Place book on desk

3. Open book to first page

4. Until end of book, Read.

Step 4 contains a few complexities. Until suggests that there is some repetition and Read could represent an algorithm also

23

Page 24: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

The algorithm describes the process that we want the computer to perform

The challenge is telling the computer how to perform that process

Page 25: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

AlgorithmsAlgorithms can specify how we access data

Page 26: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Data structuresData structures specify how data is organized

What if the phone book was not alphabetical?

Page 27: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

So what IS a program?A collection of algorithms and data structures

Page 28: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Up NextBinary

Programming Languages

Brief Introduction to PythonStatementsPython Math Library

Page 29: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

HomeworkRead Chapter 1

Read Course Policies

Signup for Piazza

Register your iclicker

Page 30: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Quick ReviewWhat is Computer Science?

What is an Algorithm?

We know that a program is a collection of implemented algorithms and data structuresHow do we develop a program?

Page 31: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

The Software Development Process

The process of creating a program is often broken down into stages according to the information that is produced in each phase.

Page 32: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

The Software Development Process

Analyze the ProblemFigure out exactly the problem to be solved. Try to understand it as much as possible.

Page 33: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

The Software Development Process

Determine SpecificationsDescribe exactly what your program will do.Don’t worry about how the program will work, but

what it will do. Includes describing the inputs, outputs, and how

they relate to one another.You can think of your assignments as providing a

specification

Page 34: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

The Software Development Process

Create a DesignFormulate the overall structure of the program.This is where the how of the program gets worked

out.You choose or develop your own algorithm that

meets the specifications.

Page 35: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

The Software Development Process

Implement the DesignTranslate the design into a computer language. In this course we will use Python.

Page 36: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

The Software Development Process

Test/Debug the ProgramTry out your program to see if it worked. If there are any errors (bugs), they need to be

located and fixed. This process is called debugging.

Your goal is to find errors, so try everything that might “break” your program!

Page 37: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

The Software Development Process

Maintain the ProgramContinue developing the program in response to

the needs of your users. In the real world, most programs are never

completely finished – they evolve over time.

Page 38: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Processor

Page 39: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

What Computers Understand

Modern (digital) computers understand two basic states:OnOff

This is represented by

high and low voltage

on a wire.

Page 40: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

A single On/Off wire represents 1 bit.

8 bits are combined together to form a byte.

Representing On/Off as 1/0 is called Binary.Binary is a base 2 number systemOur every-day numbers are base 10

Page 41: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

BinaryIn base 10, each place holder or digit position

represents a power of 10.

In binary, each place holder represents a power of 2.

• The number 135 is broken down as1*102 + 3*101 + 5*100

in base 10

Page 42: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Binary• The base determines how many digits are

available.– In base 10 there are ten digits (0 … 9)– In base 2 there are two digits (0 or 1)

• The binary number 101 is broken down as 1*22 + 0*21 + 1*20 or

4+1=5 (converted to base 10)

Page 43: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

BinaryDespite having a different base, arithmetic is the

same

Add each column and carry digits 1 + 1 = 10 as the 1 is carried

101 + 101 = 1010

Page 44: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Longer Example

001101

+ 101011

11100

11

Page 45: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Longer Example

001101

+ 101011

111000

1111

Page 46: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Longer Example

001101

+ 101011

111000

1111

Page 47: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Longer Example

001101

+ 101011

111000

1111

Page 48: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Longer Example

001101

+ 101011

111000

1111

Page 49: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Longer Example

001101

+ 101011

111000

1111

Page 50: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Longer Example

001101

+ 101011

111000

1111

Verification: 13 + 43 = 56

Page 51: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Arithmetic HardwareAll modern computers have various hardware

tasks built into them.

For addition, each column of the computation corresponds to a single wire and the 0/1 states are toggled by basic logic gates

For complex tasks this is much too tedious

Page 52: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Saying “hello” in binary

Page 53: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Hardware InstructionsOne step up from the hardware itself is a set of

hardware instructions

These are the basic elements of programming that the hardware is capable of supporting.

These are typically still very tedious as each instruction directly corresponds to a hardware element.

Page 54: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

section .text global _start, writewrite:

mov al,1 syscallret

_start: mov rax,0x0a68732f6e69622f push rax xor rax,rax mov rsi,rsp mov rdi,1 mov rdx,8 call write

exit:xor rax,raxmov rax,60 syscall

saying ‘Hello World’ with x86 assembly

Page 55: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Programming LanguagesProgramming languages are a compromise

between spoken language and formal math.

They allow humans to communicate with computers at a higher level than machine instructions

Note: Software can usually be created using different programming languages, such as Java, Python, C++, etc.

Page 56: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Languages Cont.The easier the language is for humans to use,

the harder it is for a computer to interpret.

Natural language is ambiguous:Fruit flies like bananas

There are many languages at many different ‘levels’ of complexity and convenience.

Page 57: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Grammar and SyntaxLanguages have a set grammar and syntax

Defines a “valid” program

Punctuation: “, . ! ; : ?” always follows a word in English.

Words are the basic building block in English

Page 58: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Building Blocks of PythonNumbers, booleans, strings, floating point

numbers, and variables are basic building blocks of PythonTrue for most programming languagesKeywords

Python’s grammar defines how these building blocks fit together

Page 59: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Grammar CheckWhen executing a python program IDLE will tell

you when your grammar is incorrectGiven as error messages

Page 60: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Numbers in PythonPython allows us to work with familiar base 10

numbers.This is an example of the utility of programming

languages.

Numbers in python have various types.1.0 vs 1

See Chapter 3 Section 1 for more details!

Note: Python needs to be told what type of math you want to do

Page 61: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

BooleansBooleans are truth values

True or False (both are keywords in Python)Booleans also have a type: bool

Page 62: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Python GrammarCode in python consists of one of several things

StatementFunction DeclarationFunction Call LoopConditional

Page 63: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

StatementsThese are the most basic elements in python

code

Statements fit on a single line and typicallyAssign a value to a variablePerform arithmeticPrint somethingCall functions or procedures

Page 64: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Examplesprint(“Hello”)

print(“Hello” + “World”)

print(abs(-1))

print(1.0/2.0)

print(1/2)

Page 65: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Using Python as a Calculator

In the interactive mode you can type statements for python to evaluate

>>> 4+5

9

>>> 10/2

5

>>> 10%2

0

Page 66: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Using the Math LibraryBesides (+, -, *, /, //, **, %, abs), we have lots of

other math functions available in a math library.

A library is a module with some useful definitions/functions.

Page 67: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Using the Math LibraryLet’s write a program to compute the roots of a

quadratic equation!

The only part of this we don’t know how to do is find a square root… but it’s in the math library!

2 4

2

b b acx

a

Page 68: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Using the Math LibraryTo use a library, we need to make sure this line

is in our program:

import math

Importing a library makes whatever functions are defined within it available to the program.

Page 69: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

Using the Math LibraryTo access the sqrt library routine, we need to

access it as math.sqrt(x).

Using this dot notation tells Python to use the sqrt function found in the math library module.

To calculate the root, you can dodiscRoot = math.sqrt(b*b – 4*a*c)

Page 70: Programming with Multimedia Objects CS 177 Lukasz (Luke) Ziarek BASICS Course Mechanics Expectations 1

HomeworkRead Chapter 2

Up to 2.5.3 (less than 20 pages)

Go through Pre Lab 2

Start going through the python tutorialhttp://en.wikibooks.org/wiki/Non-Programmer%

27s_Tutorial_for_Python_3 Its located toward the bottom of the python wiki

book main page