Aleksandar Kuzmanovic Northwestern University

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Python Basics: Statements Expressions Loops Strings Functions.
CS 100: Roadmap to Computing Fall 2014 Lecture 0.
EECS 110: Lec 14: Classes and Objects Aleksandar Kuzmanovic Northwestern University
Types and Arithmetic Operators
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
Lists Introduction to Computing Science and Programming I.
Introduction to Python
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
JavaScript, Third Edition
Computer Science 101 Introduction to Programming.
Computer Science 1000 Spreadsheets II Permission to redistribute these slides is strictly prohibited without permission.
EECS 110: Lec 2: What is Programming?
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Computer Science 111 Fundamentals of Programming I Number Systems.
Now String theory To Do: Lists This stuff hurts my brane. when you learn string theory from google images… Goal: Thinking like a machine You should now.
Computer Science 101 Introduction to Programming.
The last CS lecture you’ll ever need! On Warner Brothers' insistence, we affirm that this 'C' does not stand for 'Chamber' and 'S' does not stand for 'Secrets.'
EECS 110: Lec 3: Data Aleksandar Kuzmanovic Northwestern University
EECS 110: Lec 4: Functions and Recursion Aleksandar Kuzmanovic Northwestern University
More about Strings. String Formatting  So far we have used comma separators to print messages  This is fine until our messages become quite complex:
Introduction to Strings Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg 1.
Strings The Basics. Strings a collection data type can refer to a string variable as one variable or as many different components (characters) string.
The last CS lecture you’ll ever need! On Warner Brothers' insistence, we affirm that this 'C' does not stand for 'Chamber' and 'S' does not stand for 'Secrets.'
EECS 110: Lec 3: Data Aleksandar Kuzmanovic Northwestern University
EECS 110: Lec 2: What is Programming? Aleksandar Kuzmanovic Northwestern University
EECS 110: Lec 7: Program Planning Aleksandar Kuzmanovic Northwestern University
EECS 110: Lec 9: Review for the Midterm Exam Aleksandar Kuzmanovic Northwestern University
EECS 110: Lec 3: Data Aleksandar Kuzmanovic Northwestern University
CompSci Today’s topics Problem Solving Pseudocode Notes from Zachary Dodds’ CS 5 course at Harvey Mudd Upcoming ä More Python Reading Brookshear,
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 this week – last section on Friday. Assignment 4 is posted. Data mining: –Designing functions.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
ENGINEERING 1D04 Tutorial 2. What we’re doing today More on Strings String input Strings as lists String indexing Slice Concatenation and Repetition len()
String and Lists Dr. José M. Reyes Álamo.
Information and Computer Sciences University of Hawaii, Manoa
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
EECS 110: Lec 9: Review for the Midterm Exam
EECS 110: Lec 5: List Comprehensions
EECS 110: Lec 2: What is Programming?
Variables, Expressions, and IO
CMSC201 Computer Science I for Majors Lecture 03 – Operators
Strings Part 1 Taken from notes by Dr. Neil Moore
Introduction to Strings
Introduction to Strings
And now for something completely different . . .
CHAPTER THREE Sequences.
Fundamentals of Programming I Number Systems
Winter 2018 CISC101 12/1/2018 CISC101 Reminders
Data types Numeric types Sequence types float int bool list str
CISC101 Reminders Quiz 1 grading underway Next Quiz, next week.
String and Lists Dr. José M. Reyes Álamo.
EECS 110: Lec 4: Functions and Recursion
Lists Part 1 Taken from notes by Dr. Neil Moore
More elements of Python programs
Introduction to Strings
CHAPTER 3: String And Numeric Data In Python
CS1110 Today: collections.
15-110: Principles of Computing
For loops Taken from notes by Dr. Neil Moore
Introduction to Computer Science
Introduction to Strings
Python Review
COMS 261 Computer Science I
Intro to Computer Science CS1510 Dr. Sarah Diesburg
CS2911 Week 3, Lab Today Thursday Friday Review Muddiest Point Lab 3
CS 100: Roadmap to Computing
Class code for pythonroom.com cchsp2cs
Introduction to Strings
message = 'You need parentheses for chemistry !'
Strings Taken from notes by Dr. Neil Moore & Dr. Debby Keen
Presentation transcript:

Aleksandar Kuzmanovic Northwestern University EECS 110: Lec 3: Data Aleksandar Kuzmanovic Northwestern University http://networks.cs.northwestern.edu/EECS110-s17/

What is computer science (CS)? CS != programming What is computer science (CS)? Take EECS 101

What is computer science (CS)? CS != programming What is computer science (CS)? Take EECS 101 "not equal to"

a vehicle, not a destination CS != programming programming : CS :: machining : engineering grammar : literature Programming equations : mathematics CS a vehicle, not a destination

Programming as learning a foreign language What is programming? Programming as learning a foreign language 1) Expect it to be different! 2) Don’t feel you need to memorize it 3) Immersion == Experimentation

The foreign language of Python… syntax? semantics? intent? How it looks What it does What it should do name = input('Hi... what is your name? ') print # prints a blank line if name == ’Ning': # is it Ning? print( name, '??’) print(‘You must be a TA!') elif name == ‘Aleksandar’: # is it Aleksandar? print( ‘You must be an instructor!') else: # in all other cases... print( 'Welcome to Python,', name, '!')

The foreign language of Python… syntax? semantics? intent? How it looks What it does What it should do name = input('Hi... what is your name? ') print # prints a blank line if name == ’Ning': # is it Ning? print( name, '??’) print(‘You must be a TA!') elif name == ‘Aleksandar’: # is it Aleksandar? print( ‘You must be an instructor!') else: # in all other cases... print( 'Welcome to Python,', name, '!')

The foreign language of Python syntax? semantics? intent? How it looks What it does What it should do how punctuation is used the language keywords that are used use of whitespace peculiarities of formatting how behavior is affected …

Goal: Thinking like a machine Today Data! Labs at Wilkinson Lab tomorrow: Half of Homework 1 Bring your laptop if you’d like Goal: Thinking like a machine

“Kinds” of data What examples of data can you think of?

“Kinds” of data What examples of data can you think of? Video Statistics Binary (I/0, True/False) Matrices Qualitative/quantitative

What will these results be? Python (numeric) data types What will these results be? Dominant float 1 / 5 long 10**100 - 10**100 int 1 // 5 0.2 42 bool 41 + True Recessive

Python Operators Precedence Caution Level = ( ) / ** % * % / ** + - == set equal to Highest / divide ** Python Operators % remainder * % / ** power + - is equal to == > < == * = Lowest + > as usual < It's not worth remembering all these %+/* things! - I’d go with parentheses over precedence ( )

% the “mod” operator 7 % 3 8 % 3 9 % 3 16 % 7 x%2 == 0 x%y returns the remainder when x is divided by y 7 % 3 8 % 3 9 % 3 16 % 7 x%2 == 0 For what values of x are these True? x%2 == 1 x%4 == 0 What happens on these years?

Naming data >> x = 41 >> y = x + 1

Inside the machine… x = 41 y = x + 1 41 42 Computation Data Storage What's happening in python: x = 41 y = x + 1 What is happening behind the scenes: "variables as containers" 41 42 name: x type: int LOC: 300 name: y type: int LOC: 304 memory location 300 memory location 304 Computation Data Storage id, del

is a long list of memory locations Computer memory Random Access Memory (RAM) is a long list of memory locations on or off bit = 1 "bucket" of charge byte = 8 bits word = 4 bytes = 32 bits 42 name: x type: int LOC: 300 4 bytes for an int

Naming data >> x = 41 >> y = x + 1 >> x 41 42 >> x = x + y ??

Naming data >> x = 41 >> y = x + 1 >> x 41 42 >> x = x + y ?? 83 ??

Naming data >> x = 41 >> y = x + 1 >> x 41 42 >> x = x + y ?? 83 ?? 42

You need lists of numbers, as well! Are numbers enough? No! You need lists of numbers, as well! list and strings are helpful, too. str

Can all this information be represented using lists ? More complex data { 2, 3, 5, 7, 11 } ‘Many years later, as he faced the firing squad, Colonel Aureliano Buendia was to remember that distant afternoon when his father took him to discover ice.’ Text Sets Can all this information be represented using lists ? Sounds/Speech Networks Images/Video Ideas?

string functions str len + * s1 = 'ha' Given these strings s2 = 't' str(42) returns '42' converts input to a string len('42') returns 2 returns the string’s length 'XL' + 'II' returns 'XLII' concatenates strings 'VI'*7 returns 'VIVIVIVIVIVIVI' repeats strings s1 = 'ha' Given these strings s2 = 't' ‘hat’ ‘hahathathat’ What are s1 + s2 2*s1 + s2 + 2*(s1+s2)

s = 'northwestern university' String surgery s = 'northwestern university' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 s[ ] indexes into the string, returning a one-character string index s[0] returns 'n' Read "s-of-zero" or "s-zero" s[12]returns S[ ] returns 'h' Which index returns 'e'? s[len(s)] returns python != English

s = 'northwestern university' String surgery s = 'northwestern university' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 s[ ] indexes into the string, returning a one-character string index s[0] returns 'n' Read "s-of-zero" or "s-zero" s[12]returns ' ' S[ ] returns 'h' Which index returns 'e'? s[len(s)] returns python != English

s = 'northwestern university' String surgery s = 'northwestern university' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 s[ ] indexes into the string, returning a one-character string index s[0] returns 'n' Read "s-of-zero" or "s-zero" s[12]returns ' ' S[4] returns 'h' Which index returns 'e'? s[len(s)] returns python != English

s = 'northwestern university' String surgery s = 'northwestern university' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 s[ ] indexes into the string, returning a one-character string index s[0] returns 'n' Read "s-of-zero" or "s-zero" s[12]returns ' ' S[4] returns 'h' Which index returns 'e'? s[len(s)] returns ERROR python != English

s = 'northwestern university' Negative indices… 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 s = 'northwestern university' -23 -21 -19 -17 -15 -13 -11 -9 -7 -5 -3 -1 -22 -20 -18 -16 -14 -12 -10 -8 -6 -4 -2 Negative indices count backwards from the end! s[-1] returns 'y' S[-11] = ‘ ‘ S[-0] = n s[-11] returns s[-0] returns

s = 'northwestern university' Slicing s = 'northwestern university' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 s[ : ] slices the string, returning a substring What's going on here? s[0:5] returns 'north' s[5:9] returns 'west' s[17:] returns 'ersity' s[:] returns 'northwestern university'

s = 'northwestern university' Slicing s = 'northwestern university' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 s[ : ] slices the string, returning a substring the first index is the first character of the slice the second index is ONE AFTER the last character a missing index means the end of the string s[0:5] returns 'north' s[5:9] returns 'west' s[17:] returns 'ersity' s[:] returns 'northwestern university'

s = 'northwestern university' Skip-slicing s = 'northwestern university' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 s[ : : ] skip-slices, returning a subsequence the third index is the "stride" length it defaults to 1 s[0:8:2] returns 'nrhe' 'ruv' What skip-slice returns What does this return? s[1::6]

s = 'northwestern university' Skip-slicing s = 'northwestern university' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 s[ : : ] skip-slices, returning a subsequence the third index is the "stride" length it defaults to 1 s[0:8:2] returns 'nrhe' 'ruv' s[10:17:3] What skip-slice returns What does this return? s[1::6]

s = 'northwestern university' Skip-slicing s = 'northwestern university' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 s[ : : ] skip-slices, returning a subsequence the third index is the "stride" length it defaults to 1 s[0:8:2] returns 'nrhe' 'ruv' s[10:17:3] What skip-slice returns What does this return? s[1::6] 'osus'

Lists ~ Strings of anything Commas separate elements. Lists ~ Strings of anything L = [ 3.14, [2,40], 'third', 42 ] Square brackets tell python you want a list. len(L) L[0] Indexing: could return a different type Slicing: always returns the same type L[0:1] How could you extract from L 'hi'

Lists ~ Strings of anything Commas separate elements. Lists ~ Strings of anything L = [ 3.14, [2,40], 'third', 42 ] Square brackets tell python you want a list. len(L) 4 L[0] Indexing: could return a different type Slicing: always returns the same type L[0:1] How could you extract from L 'hi'

Lists ~ Strings of anything Commas separate elements. Lists ~ Strings of anything L = [ 3.14, [2,40], 'third', 42 ] Square brackets tell python you want a list. len(L) 4 L[0] 3.14 Indexing: could return a different type Slicing: always returns the same type L[0:1] How could you extract from L 'hi'

Lists ~ Strings of anything Commas separate elements. Lists ~ Strings of anything L = [ 3.14, [2,40], 'third', 42 ] Square brackets tell python you want a list. len(L) 4 L[0] 3.14 Indexing: could return a different type Slicing: always returns the same type L[0:1] [3.14] How could you extract from L 'hi'

Lists ~ Strings of anything Commas separate elements. Lists ~ Strings of anything L = [ 3.14, [2,40], 'third', 42 ] Square brackets tell python you want a list. len(L) 4 L[0] 3.14 Indexing: could return a different type Slicing: always returns the same type L[0:1] [3.14] How could you extract from L 'hi' L[2][1:3]

message = 'You need parentheses for chemistry !' "Quiz" Raising and razing lists Name(s): pi = [3,1,4,1,5,9] Q = [ 'pi', "isn't", [4,2] ] message = 'You need parentheses for chemistry !' Part 1 Part 2 len(pi) Q[0] What are len(Q) Q[0:1] len(Q[1]) What are Q[0][1] Q[1][0] What slice of pi is [3,1,4] What slice of pi is [3,4,5] What is message[9:15] What are pi[0] * (pi[1] + pi[2]) and pi[0] * (pi[1:2] + pi[2:3]) What is message[::5] Extra! Mind Muddlers What is pi[pi[2]]? How many nested pi's before pi[…pi[0]…] produces an error?

message = 'You need parentheses for chemistry !' "Quiz" Raising and razing lists Name(s): pi = [3,1,4,1,5,9] Q = [ 'pi', "isn't", [4,2] ] message = 'You need parentheses for chemistry !' Part 1 Part 2 len(pi) Q[0] What are len(Q) Q[0:1] len(Q[1]) What are Q[0][1] Q[1][0] What slice of pi is [3,1,4] What slice of pi is [3,4,5] What is message[9:15] What are pi[0] * (pi[1] + pi[2]) and pi[0] * (pi[1:2] + pi[2:3]) What is message[::5] Extra! Mind Muddlers What is pi[pi[2]]? How many nested pi's before pi[…pi[0]…] produces an error?