CS 105 SUMMER WEDNESDAY 7 What to talk about today? From Reading - - PowerPoint PPT Presentation

cs 105 summer wednesday 7 what to talk about today
SMART_READER_LITE
LIVE PREVIEW

CS 105 SUMMER WEDNESDAY 7 What to talk about today? From Reading - - PowerPoint PPT Presentation

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 Quiz 6


slide-1
SLIDE 1

CS 105 SUMMER – WEDNESDAY 7

slide-2
SLIDE 2

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

slide-3
SLIDE 3

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

slide-4
SLIDE 4

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

slide-5
SLIDE 5

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

slide-6
SLIDE 6

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)

slide-7
SLIDE 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.

slide-8
SLIDE 8

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/

slide-9
SLIDE 9

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

slide-10
SLIDE 10

One other quick MP

Quote: "yuiyuyuy"

slide-11
SLIDE 11

List Nesting

slide-12
SLIDE 12

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."

slide-13
SLIDE 13

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]?

slide-14
SLIDE 14

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"

slide-15
SLIDE 15

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"] ]

slide-16
SLIDE 16

Why nest lists?

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

(I'm sorry)

slide-17
SLIDE 17

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?

slide-18
SLIDE 18

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!

slide-19
SLIDE 19

List Sorting

slide-20
SLIDE 20

List sorting

 Some MPs talk about sorting with a "loop"  In Python – don't bother  Two kinds of sort

Sort 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()

slide-21
SLIDE 21

Modifying a list while loop through it

slide-22
SLIDE 22

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]

slide-23
SLIDE 23

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

slide-24
SLIDE 24

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

slide-25
SLIDE 25

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?

slide-26
SLIDE 26

Keyword Arguments and Default Values

slide-27
SLIDE 27

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"

slide-28
SLIDE 28

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"

slide-29
SLIDE 29

Python named arguments

 What happens here?  def my_function(num1 = 5, num2, num3 = 10):

 print(num1+num2+num3)

 my_function(10, 10, 20)

slide-30
SLIDE 30

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

slide-31
SLIDE 31

Excel By Example

slide-32
SLIDE 32

Excel by example

I downplayed the harder excel this summer For learning, let's look at the excel homework 13.2, 13.3

slide-33
SLIDE 33

12.14, 12.15, 13.11, 13.13

Identified Homework Problems