CS 105 SUMMER WEDNESDAY 3 What to talk about today? From the - - PowerPoint PPT Presentation
CS 105 SUMMER WEDNESDAY 3 What to talk about today? From the - - PowerPoint PPT Presentation
CS 105 SUMMER WEDNESDAY 3 What to talk about today? From the muddiest points String Formatting... (Including directly looking at the 'X in line' variant) Return vs print When do we use lists? Dictionaries? Boolean
What to talk about today?
From the muddiest points
String Formatting... (Including directly looking at the 'X in line' variant) Return vs print When do we use lists? Dictionaries?
Boolean expressions I want to touch on
The use of the 'in' operator The use of short circuiting
Challenge questions you want me to hit? Homework you want me
to hit?
Some things not to worry about
Do you need to memorize binary and hex?
No – although binary is super easy with a bit of practice!
Hypothesis testing
Useful, but largely in the reading for interest/relation to functions
"What excel do I need to know?" – When you need it, the reading topic
will include it
We get as far as V/HLookUp as far as task complexity, probably
second half of next week onward
Tuples and sets – largely deemphasizing them
Although sets do have a use – let's check unique elements of a list!
Quiz 2 comments
High level stats:
Mean 82%, Median 87% Pretty good
Office hours, office hours Practice – there is some redundancy! (Do all the homework) Better content curve
Quiz 3's programming will focus on conditionals (this week's reading),
some expressions
Quiz 4 may dip back into string formatting – but the practice will
reflect this!
https://kpwritesb log.files.wordpre ss.com/2017/10 /fireworks- animation-33- 2.gif?w=300&h =294&crop=1
String Formatting
Let's take a look at HW 4.15 and 4.34 Then let's also try
A string with an integer and a floating point Looking at the Python string formatting docs https://docs.python.org/3/library/string.htm
l#formatspec
Return vs Print (also function calls)
Return is used to return a value to a place You touched on modularization in lab yesterday
(although lab was a bit large…)
Print just prints output to console Let's consider – function which calculates price used
to calculate a shopping list
List and dictionary usage
You can use lists whenever you want a non-unique stack of "stuff"
In practice, data type tends to be the same, although it does not
HAVE to be
This is how Java lists differ from, say, ArrayLists in Java
Dictionary usage is a bit more clear
I have a key for a value I have a name for an address I have a user_name for a list of data I have a company name for a company object (departments,
employees, etc.)
What about sets and tuples?
Sets enforce uniqueness, but…
So can lists with in – let's see an example
Tuples I personally only ever use in reference to the
data analysis module pandas
I've never used named tuples - they're like mini objects from collections import namedtuple
Person = namedtuple('Person', 'first_name last_name
zip_code')
p1 = Person('Joe', 'Schmoe', '93002')
Boolean Expressions – the use of in
The in operator is used to check for membership in
a collection
I'd like to check…
If a string contains 'hello' If the list ['h', 'ello'] contains 'hello' if the list, ['hello world', 'I need coffee'] contains
'hello'
Short Circuit
Think about this prompt:
"If a number is even and positive, return the number multiplied by 2."
If the number is odd, do you need to check if it is
positive?
Short circuit – a more salient example
"If the parameter is a number and it is even,
return its square root"
vs "If something is even and a number, return its
square root"
That was my planned content
If there are no questions, we will at least go
- ver…