EECS 110: Lec 3: Data Aleksandar Kuzmanovic Northwestern University

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Visual Basic Statements Chapter 5. Relational Operators  OperationSymbol  Equal  =  Less than  <  Greater than  >  Not equal   Less than.
EECS 110: Lec 14: Classes and Objects Aleksandar Kuzmanovic Northwestern University
Types and Arithmetic Operators
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
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.
Today’s whether: if, elif, or else!
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.
Data Types. Every program must deal with data The data is usually described as a certain type This type determines what you can do with the data and how.
Computer Science 1000 Spreadsheets II Permission to redistribute these slides is strictly prohibited without permission.
Introduction to Python
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.
Data Structures in Python By: Christopher Todd. Lists in Python A list is a group of comma-separated values between square brackets. A list is a group.
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.
EECS 110: Lec 5: List Comprehensions Aleksandar Kuzmanovic Northwestern University
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
Built-in Data Structures in Python An Introduction.
EECS 110: Lec 4: Functions and Recursion Aleksandar Kuzmanovic Northwestern University
Introduction to Python and programming Ruth Anderson UW CSE 140 Winter
More about Strings. String Formatting  So far we have used comma separators to print messages  This is fine until our messages become quite complex:
CS2910 Week 2, Class 1 Today Data Encoding, Part 1 Parsing Data Python Muddiest Point Lab 2 – Bring text In Class, Thursday: Quiz Week 6, Monday: Midterm.
Introduction to Strings Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg 1.
Strings Mr. Smith AP Computer Science A. What are Strings? Name some of the characteristics of strings: A string is a sequence of characters, such as.
COMP Primitive and Class Types Yi Hong May 14, 2015.
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.'
Python Let’s get started!.
EECS 110: Lec 3: Data Aleksandar Kuzmanovic Northwestern University
Introduction to Objective Caml. General comments ML is a purely functional language--there are (almost) no side effects There are two basic dialects of.
EECS 110: Lec 7: Program Planning Aleksandar Kuzmanovic Northwestern University
EECS 110: Lec 9: Review for the Midterm Exam Aleksandar Kuzmanovic Northwestern University
PYTHON VARIABLES : CHAPTER 2 FROM THINK PYTHON HOW TO THINK LIKE A COMPUTER SCIENTIST.
The last CS 5 lecture you’ll ever need! Inducing labor for the machine! == Reducing labor for humans! On Warner Brothers' insistence, we affirm that this.
EECS 110: Lec 12: Mutable 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,
Expressions Version Topics Arithmetic expressions Conversions Operator precedence String class 2.
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.
Mr. Crone.  Use print() to print to the terminal window  print() is equivalent to println() in Java Example) print(“Hello1”) print(“Hello2”) # Prints:
String and Lists Dr. José M. Reyes Álamo.
EECS 110: Lec 9: Review for the Midterm Exam
Variables and Expressions
Aleksandar Kuzmanovic Northwestern University
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.
Data types Numeric types Sequence types float int bool list str
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
Introduction to Strings
CHAPTER 3: String And Numeric Data In Python
CS1110 Today: collections.
Introduction to Computer Science
Introduction to Strings
Python Review
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:

EECS 110: Lec 3: Data Aleksandar Kuzmanovic Northwestern University

If statements (1) 2 name = raw_input('Hi... what is your name? ') if name == 'Ionut': # is it Ionut? print 'x1' else: # in all other cases... print 'x2' print 'x3'

If statements (2) 3 name = raw_input('Hi... what is your name? ') if name == 'Ionut‘: print 'x1' else: print 'x2' print 'x3'

If statements (3) 4 name = raw_input('Hi... what is your name? ') if name == 'Ionut': # is it Ionut? print 'x1' elif name == 'Aleksandar': print 'x2' else: # in all other cases... print 'x3' print 'x4'

If statements (4) 5 name = raw_input('Hi... what is your name? ') if name == 'Ionut': print 'x1' elif name == 'Aleksandar': print 'x2' else: print 'x3' print 'x4'

If statements (5) 6 name = raw_input('Hi... what is your name? ') if name == 'Ionut': # is it Ionut? print 'x1' elif name == 'Aleksandar': print 'x2' elif name == 'Lisa': print 'x3' else: # in all other cases... print 'x4' print 'x5'

If statements (6) 7 name = raw_input('Hi... what is your name? ') if name == 'Ionut‘: print 'x1' elif name == 'Aleksandar’: print 'x2' elif name == 'Lisa': print 'x3' else: print 'x4' print 'x5'

8 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? 9

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

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

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

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

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

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

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

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

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

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

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

Networks Images/Video Sounds/Speech { 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 Ideas? Can all this information be represented using lists ? More complex data

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

s[ ] indexes into the string, returning a one-character string s = 'northwestern university' s[0] returns 'n' s[12] returns S[ ] returns 'h' Which index returns 'e'? python != English s[len(s)] returns Read "s-of-zero" or "s-zero" index String surgery

s[ ] indexes into the string, returning a one-character string s = 'northwestern university' s[0] returns 'n' s[12] returns ' ' S[ ] returns 'h' Which index returns 'e'? python != English s[len(s)] returns Read "s-of-zero" or "s-zero" index String surgery

s[ ] indexes into the string, returning a one-character string s = 'northwestern university' s[0] returns 'n' s[12] returns ' ' S[4] returns 'h' Which index returns 'e'? python != English s[len(s)] returns Read "s-of-zero" or "s-zero" index String surgery

s[ ] indexes into the string, returning a one-character string s = 'northwestern university' s[0] returns 'n' s[12] returns ' ' S[4] returns 'h' Which index returns 'e'? python != English s[len(s)] returnsERROR Read "s-of-zero" or "s-zero" index String surgery

s = 'northwestern university' Negative indices… Negative indices count backwards from the end! s[-1] returns 'y' s[-11] returns s[-0] returns

s[ : ] slices the string, returning a substring s[5:9] returns 'west' s[0:5] returns 'north' What's going on here? s[17:] returns 'ersity' s[:] returns 'northwestern university' Slicing s = 'northwestern university'

s[ : ] slices the string, returning a substring s[5:9] returns 'west' s[0:5] returns 'north' s[17:] returns 'ersity' s[:] returns 'northwestern university' Slicing s = 'northwestern university' 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

Skip-slicing s = 'northwestern university' s[ : : ] skip-slices, returning a subsequence the third index is the "stride" length it defaults to 1 s[0:8:2] returns 'nrhe' What skip-slice returns What does this return? 'ruv' s[1::6]

Skip-slicing s = 'northwestern university' s[ : : ] skip-slices, returning a subsequence the third index is the "stride" length it defaults to 1 s[0:8:2] returns 'nrhe' What skip-slice returns What does this return? 'ruv' s[10:17:3] s[1::6]

Skip-slicing s = 'northwestern university' s[ : : ] skip-slices, returning a subsequence the third index is the "stride" length it defaults to 1 s[0:8:2] returns 'nrhe' What skip-slice returns What does this return? 'ruv' s[10:17:3] s[1::6] 'osus'

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

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

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

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

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

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