CS 105 SUMMER WEDNESDAY 4 What to talk about today? From the - - PowerPoint PPT Presentation

cs 105 summer wednesday 4
SMART_READER_LITE
LIVE PREVIEW

CS 105 SUMMER WEDNESDAY 4 What to talk about today? From the - - PowerPoint PPT Presentation

CS 105 SUMMER WEDNESDAY 4 What to talk about today? From the muddiest points Complex inequalities chaining relational and logical operators Challenge 6.5.4 is a good example of this Function usage (calling) and anatomy


slide-1
SLIDE 1

CS 105 SUMMER – WEDNESDAY 4

slide-2
SLIDE 2

What to talk about today?

From the muddiest points

Complex inequalities – chaining relational and logical

  • perators

Challenge 6.5.4 is a good example of this

Function usage (calling) and anatomy (writing)

Your questions – please feel free to post

questions you'd like to see in chat! Otherwise, think 6.33, 6.34, 7.26, 7.27

slide-3
SLIDE 3

Quick muddiest points

 Indentation?

 Please use tab for every code block

 Largely a PL issue – the editor handles tab

better than space

def function_name(): statement statement if True: statements

  • Global/main scope – no

indent

  • Function scope for

function_name

  • Scope inside the if

Statement

slide-4
SLIDE 4

Quick muddiest points

I found myself wondering why you would use ternary/conditional expressions instead

  • f breaking them up into more easily digestable bits. Is it just a style thing or is there a

reason you would use one or the other? I am interested in more information in regard of the conditional expression. It is basically a short-version of a single if-else statement. Why do we need conditional expression? The if-else statement can express the same meaning; and with nested statements, if-else statements can exam more conditions than the conditional expression.

 I'm with you here, even though I sometimes use the shorthand  Old style code – write as little as possible, people prided themselves on being

  • btuse

 Modern software engineering – self documenting, legible code is better  Most useful for lambdas (out of course scope) and list comprehensions (later on)

slide-5
SLIDE 5

Quick muddiest points

I heard people say that if statement occupies a lot of computer resources. Is that true?

 Nah fam

Python is operator

 You should generally use == for equality in this class  is operator is used to check if two OBJECTS are the same  For example:

 list1 = [1,2,3]  list2 = list1  print(list1 is list2)

slide-6
SLIDE 6

Quiz 3 comments

High level stats: Mean 80%, Median 83% Perspective – each quiz is 5%. Take your score and

multiply by .05 – an exact 75% is 3.75/5 of the final

points!

 Most commonly missed questions are questions that weren't

done on HW5 or related to those questions…Q 5.38, Q 5.39

slide-7
SLIDE 7

Practice Quiz 4

Better match to quiz 4 than PQ3 was to 3, so

please be sure to take it at least once!

Topics – Up through loops, but not the harder

excel content from HW7/Topic

Specific programming content:

String formatting is back, conditionals rehash,

loops

slide-8
SLIDE 8

From the muddiest points…

I find myself frustrated a lot because the book’ s examples are like building a bookshelf, but the homework is like building a birdhouse. You need to nail wood with a hammer like the book taught, but the way to reach the end goal is slightly different.

 Superb insight  To scaffold…

The book => bookshelves The homework => birdhouses The quizzes =>

mostly birdhouses, sometimes with different paint. Sometimes dollhouses

slide-9
SLIDE 9

Relational and Logical Operators

 Python has the

core set, as we'd expect

 Order of ops

between them?

 ==, !=, <= ,

>=, >, <

slide-10
SLIDE 10

Logical Operators

Python has three – not, and, or Their precedence is also exactly that – not before

and before or

Given this statement: not False and True or False

((not False) and True) or False (True and True) or False True or False True

slide-11
SLIDE 11

Python also has…

in and not in Key piece of setting up for loops Also useful for conditionals "Add a key to a dictionary if it isn't already in the

dictionary"

slide-12
SLIDE 12

Two ways to do it: not in vs in

if new_key not in the_dict:

the_dict[new_key] = nv

#Assuming a loop… if new_key in the_dict: continue the_dict[new_key] = nv

slide-13
SLIDE 13

Checking two variables Maybe also homework 7.31

Challenge 6.5.4

slide-14
SLIDE 14

Function anatomy

Reminder – a function has:

def print_a_name(name): print("Hello " + name + "!") A header: with parameters and function name A body – what the function DOES

slide-15
SLIDE 15

Functions

You've been calling functions since you first used

input()

Calling a function is just the function name,

parenthesis, and the arguments needed for the parameters

Examples:

my_name = input() print_a_name(my_name)

slide-16
SLIDE 16

Homework/reading disconnect - Functions

In this class, we are at most asking you to write a

function per question

You generally aren't calling functions, unless they

are:

Short answer questions – asking you to call one Methods of an existing object, like .append() Standard library functions, like input()

slide-17
SLIDE 17

How are your functions graded?

A lesson on function use and scope Let's look at how Q 5.35 would be

graded!

slide-18
SLIDE 18

6.33, 6.33, 7.26, 7.27

Homework questions

slide-19
SLIDE 19

Next week

I think I'd like to do the bee movie script thing Wanted to do it this week, but I want to make

sure I pick the correct SMS options for free testing…