cs 105 summer wednesday 4
play

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


  1. CS 105 SUMMER – WEDNESDAY 4

  2. 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 (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

  3. Quick muddiest points  Indentation? • Global/main scope – no  Please use tab for every code block indent  Largely a PL issue – the editor handles tab better than space • Function scope for def function_name(): function_name statement statement • Scope inside the if if True: Statement statements

  4. Quick muddiest points I found myself wondering why you would use ternary/conditional expressions instead of 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 obtuse  Modern software engineering – self documenting, legible code is better  Most useful for lambdas (out of course scope) and list comprehensions (later on)

  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)

  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

  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

  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

  9. Relational and Logical Operators  Python has the core set, as we'd expect  Order of ops between them?  ==, !=, <= , >=, >, <

  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

  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"

  12. Two ways to do it: not in vs in if new_key not in the_dict: #Assuming a loop… the_dict[new_key] = nv if new_key in the_dict: continue the_dict[new_key] = nv

  13. Challenge 6.5.4 Checking two variables Maybe also homework 7.31

  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

  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)

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

  17. How are your functions graded?  A lesson on function use and scope  Let's look at how Q 5.35 would be graded!

  18. Homework questions 6.33, 6.33, 7.26, 7.27

  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…

Recommend


More recommend