cs 105 summer wednesday 7

33
CS 105 SUMMER WEDNESDAY 7

Upload: others

Post on 16-Oct-2021

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 105 SUMMER WEDNESDAY 7

CS 105 SUMMER –

WEDNESDAY 7

Page 2: CS 105 SUMMER WEDNESDAY 7

What to talk about today?

From Reading 10/11

Nested lists

List sorting

Modifying a list when looping through it

From Reading 12

Keyword arguments and default values

Also excel

Page 3: CS 105 SUMMER WEDNESDAY 7

Quiz 6 comments

High level stats: Mean 83% - Nice job!

Code Reading question seemed to go well

Some adjustments:

Programming questions – more attempts (but worth

more points) so less questions on Q7.

Two attempts on CDRD question on Quiz 7

Speaking of CDRD – that study I emailed

Page 4: CS 105 SUMMER WEDNESDAY 7

Practice Quiz 7

Has been up since Monday

Another good reflection of the Quiz

Wide programming net – pulling from

HW 8-13

Still not harder excel stuff

Page 5: CS 105 SUMMER WEDNESDAY 7

Other course announcement stuff

Reminder – ALL ZyBooks finished before reading day will get full credit, as will videos watched

Plan to update grades – later today, Sunday, and reading day

Please check your lab credit – if you know you're missing some, private Piazza post

Will probably produce some help videos for next week, but won't mandate watching

Page 6: CS 105 SUMMER WEDNESDAY 7

Notes for next week

Effectively like "finals" week plus a final week of class stuff

Last Lab – review for finals

Last Wednesday – review for finals and the bee movie script thing as promised

Last homework? Not a homework – just doing the

practice final at least once (when it is up!) (Full homework score regardless of performance)

Page 7: CS 105 SUMMER WEDNESDAY 7

There were a LOT of MPs on html

I found basic HTML tags confusing because they have multiple tags that render the same result such as <em>, <cite> and <italic>. Would it matter if I use <italic> instead of <cite>? They also have a lot of different tags which can be confusing.

I would like to learn more about basic HTML tags as well as lists and tables as I found these sections to be the most confusing in the text as I discuss in the previous question.

The muddiest point was probably the section about tables. In all honesty, the entire section was a little muddy. I know that most of what we learned here is pretty intuitive but there's just kind of a lot to keep in mind, especially in the tables section.

Page 8: CS 105 SUMMER WEDNESDAY 7

We don't test much HTML content - but

If we have time today, I can take more questions

Otherwise, I can answer other questions on Piazza

– I don't mind

Next lab goes into HTML quite a bit

Finally, a more "gentle" intro than the book

https://www.w3schools.com/html/

Page 9: CS 105 SUMMER WEDNESDAY 7

Couple quick MPs

" I don't understand exactly how to use the .pop() function. How

does it differ from the .remove() function?"

Answer: .pop() removes by index location. .remove() removes by

matching value

"(in the videos) Solving some homework and practice quiz problems

would also be a really awesome tool to help people understand

stuff better"

Answer: That's what I do on Wednesdays, partially…also office

hours

Page 10: CS 105 SUMMER WEDNESDAY 7

One other quick MP

Quote: "yuiyuyuy"

Page 11: CS 105 SUMMER WEDNESDAY 7

List Nesting

Page 12: CS 105 SUMMER WEDNESDAY 7

List nesting MPs

"I believe list nesting was the most confusing concept"

"I would like more details about when list nesting would be an

ideal option for someone who is trying to get the desired output

for a function, code, etc."

"In this section I thought that list nesting was a little confusing,

especially trying to identify what value would be returned by a

given index."

Page 13: CS 105 SUMMER WEDNESDAY 7

List Nesting

High level – a LIST of LISTS

my_list =

[["puffin", "muffin"],

["dog", 'frog"],

["bat", 'cat"]]

What do you think my_list[1][2] is?

How about my_list[1][0]?

Page 14: CS 105 SUMMER WEDNESDAY 7

List Nesting

Need to access with multiple indices

my_list = [[…],[…],[…]]

my_list[#] – the whole list (row) at index #

my_list[a][b] – the element in row a and position b

No easy way to loop "by column"

Page 15: CS 105 SUMMER WEDNESDAY 7

Why nest lists?

Use case 1) Like a table!

A B C D

E F G H

I J K L

M N O P

[

["A","B","C","D"],

["E","F","G","H"],

["I", "J", "K", "L"],

["M","N","O", "P"]

]

Page 16: CS 105 SUMMER WEDNESDAY 7

Why nest lists?

Use case 2) like a battleship or chess board!!!

(I'm sorry)

Page 17: CS 105 SUMMER WEDNESDAY 7

Why nest lists?

Use case 3) for some sort of related data structure

Example – a list of employees in different departments

Department_list =

[

["Bob", "Karen", "Cindy"],

["Rachel", "Alice"],

["Beomjin", "David", "Kaye"]

]

Each row is a department!

…Can anyone think of a better option than nested lists?

Page 18: CS 105 SUMMER WEDNESDAY 7

Department use case – also a case for dictionaries!

{

"Department X": ["Bob", "Karen", "Cindy"],

"Department Y": ["Rachel", "Alice"],

"Department Z": ["Beomjin", "David", "Kaye"]

}

In the long run, it is up to you what data structures are best for a situation

Largely – the same kinds of use cases as nested loops, since nested loops

can operate over nested lists!

Page 19: CS 105 SUMMER WEDNESDAY 7

List Sorting

Page 20: CS 105 SUMMER WEDNESDAY 7

List sorting

Some MPs talk about sorting with a "loop"

In Python – don't bother

Two kinds of sortSort in place: my_list.sort()

Make a sorted copy: my_copy = sorted(my_list)

"Can python only do smallest to largest?"

Nope!reverse= True can be an argument to either of them!

Note - .sort() is not the same as .reverse()

Page 21: CS 105 SUMMER WEDNESDAY 7

Modifying a list while loop through it

Page 22: CS 105 SUMMER WEDNESDAY 7

What will be the data stored in my_list?

my_list = [1,2,3,4]

for num in my_list:

num += 2

print(my_list)

A) [1,2,3,4]

B) B) [3, 4, 5, 6]

Page 23: CS 105 SUMMER WEDNESDAY 7

Lists are mutable, but…

for loops don't access the memory – they fetch the

values

To modify a list, we need to either

1. Use range

2. Use enumerate

Page 24: CS 105 SUMMER WEDNESDAY 7

These loops both update the list by adding 5 to

each element

my_list = [1,2,3]

for i in range(len(my_list)):

my_list[i] = my_list[i] + 5

my_list = [1,2,3]

for i,val in enumerate(my_list):

my_list[i] = val + 5

Page 25: CS 105 SUMMER WEDNESDAY 7

Other list modifications

Danger – adding to a list in a loop!!!

for element in my_list:

my_list.append(5)

#How does the loop end?

Page 26: CS 105 SUMMER WEDNESDAY 7

Keyword Arguments and Default Values

Page 27: CS 105 SUMMER WEDNESDAY 7

Python arguments

parameters are variables that hold the values of

arguments when a function is called

def a_function(param1, param2):

a_function(5, "puffin")

5 "puffin"

Page 28: CS 105 SUMMER WEDNESDAY 7

Python default arguments

parameters are also keyword names for arguments – if we

give them a default

def a_function(param1, param2="red panda")

a_function(5, param2

="puffin")

5 "puffin""red panda"

Page 29: CS 105 SUMMER WEDNESDAY 7

Python named arguments

What happens here?

def my_function(num1 = 5, num2, num3 = 10):

print(num1+num2+num3)

my_function(10, 10, 20)

Page 30: CS 105 SUMMER WEDNESDAY 7

Python argument fast rules

1. keyword arguments are parameters which have a

default – optional

2. positional arguments are parameters without a default

– data MUST be passed for the function to be called

3. positional must come BEFORE keywords

Page 31: CS 105 SUMMER WEDNESDAY 7

Excel By Example

Page 32: CS 105 SUMMER WEDNESDAY 7

Excel by example

I downplayed the harder excel this summer

For learning, let's look at the excel homework

13.2, 13.3

Page 33: CS 105 SUMMER WEDNESDAY 7

12.14, 12.15, 13.11, 13.13

Identified Homework Problems