1 / 53

CSE 115

CSE 115. Introduction to Computer Science I. Announcements. Un graded labs & recitations this week Attend scheduled section if it meets Tues. – Fri. If yours was cancelled, can attend replacement Since this week's lab is ungraded, no requirements in UBInfinite for lab. Announcements.

nathanz
Download Presentation

CSE 115

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSE 115 Introduction to Computer Science I

  2. Announcements • Ungraded labs & recitations this weekAttend scheduled section if it meets Tues. – Fri.If yours was cancelled, can attend replacement • Since this week's lab is ungraded, no requirements in UBInfinite for lab

  3. Announcements • Graded labs & recitations starts next weekMust attend YOUR section; system limits accessLab work submitted outside Baldy 21 will be given 0: must submit work from lab computers. • Must have 3 stars on bothModule 1's Expressions&VariablesBEFORE your lab next weekEnforced by the system; TAs cannot do anything about itCannot sit in lab to complete; TAs must ask you to leave

  4. Announcements Graded TopHatquestions starts today • Calling Function & Defining FunctionMay need both lectures for UBInfinite exercisesEven if you cannot finish, good idea to try starting work after class • repl.it helps solve UBInfinite questionsOnly 1st answer earns credit, so make it countOnce code works, copy-and-paste answer back into UBInfinite

  5. Help us help you! Search Piazza before posting: question might be answered When posting to Piazza:

  6. Help us help you! Search Piazza before posting: question might be answered When posting to Piazza: Tell us what YOU think problem is

  7. Help us help you! Search Piazza before posting: question might be answered When posting to Piazza: Tell us what YOU think problem is What you've tried to solve problem on your own

  8. Help us help you! Search Piazza before posting: question might be answered When posting to Piazza: Tell us what YOU think problem is What you've tried to solve problem on your own Explain which topic is confusing or hard-to-understand

  9. Help us help you! Search Piazza before posting: question might be answered When posting to Piazza: Tell us what YOU think problem is What you've tried to solve problem on your own Explain which topic is confusing or hard-to-understand Developing good learning strategies is important part of class; upper-level classes (and bosses) need more than saying 'help'

  10. Today's Plan Review Calling functions repl.itDemo: function calls in Python

  11. REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW Variable Key Concept Namethat has beenassigned avalue

  12. REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW Variables Assignment name=expression assign1) namewritten on left-handsideof assignment operator assign3) expressionwritten onright-handsideof assignment operator assign2) write the assignment operator

  13. REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW Variables in Expressions Variables also expressions After assigned value, variable usable as simple expression:x = 3interesting_name = 6interesting_name = xprint(x * 5)school_name = 'UB'mascot = (school_name + " ") + "Bulls"

  14. REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW Writing a Compound Expression Subgoals • exp1) Determine the left-hand side of the expression • a) Write the left-hand subexpressionb) Determine the type for the value this subexpression evaluates to • exp2) Write the operator • exp3) Determine the right-hand side of the expression • a) Write the right-hand subexpressionb) Determine the type for the value this subexpression evaluates to • exp4) Verify operator valid for subexpressions' types

  15. REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW Writing an Assignment Subgoals • assign1) Write the name of the variable • assign2) Write the assignment operator • assign3) Write the expression whose value will be assigned to the variable

  16. Today's Plan Review Calling functions Demo: function calls in Python

  17. Functions Function is named block of code Executecode suiteby calling the function Code a function callby typing name &providing arguments Good for common tasks, since can call function anytime

  18. Functions Original Ideas From Math

  19. Expressions Function Calls Calling function like hiring it to have it step in & do its thing Function does all of work, you get any result it produces Function calls are another type of expression:Function name is operationArgument(s) are subexpression(s)

  20. Functions Python includes many built-in functions abs(num)min(num_1,num_2)max(num_1,num_2)pow(a_name,other_name)round(consistency_sucks)round(x,y)print(value_to_print)

  21. Imports Also has functions defined in modules Must importmodule to use these functions Example using Python's math module import math hope_close_enough = math.sin(3.141592) module_also_has_constants = math.pi/2 shorter = module_also_has_constants print( math.cos( shorter ) * 4 )

  22. Writing a Function Call Expression Subgoals • fc1) Write the function name • fc2) Write the argument lista) Start the argument list with an open parenthesisb) For each of function's input(s) in listed order, write the expression whose value is used for that inputc) Write a comma between each pair of argumentsd) End the argument list with a close parenthesis

  23. Function Calls Examples pow( 3 , 2 ) min( 16/3, 4 ) • print( "Hi there!" ) x = -6y = abs(x) fc1) Write the functionname

  24. Function Calls • Examples • pow( 3 , 2 ) • min( 16/3, 4 ) • print( "Hi there!" ) • x = -6y = abs(x) fc2a)Start argumentlistwithopen parenthesis

  25. Function Calls • Examples • pow(3 , 2 ) • min( 16/3, 4 ) • print("Hi there!" ) • x = -6y = abs(x) fc2b)Write expressionswhose values used for that input

  26. Function Calls • Examples • pow(3 , 2 ) • min( 16/3, 4 ) • print("Hi there!" ) • x = -6y = abs(x) fc2c)Write a commabetween each pairof arguments

  27. Function Calls • Examples • pow(3 , 2 ) • min( 16/3, 4 ) • print("Hi there!" ) • x = -6y = abs(x) fc2d)End the argument list with a close parenthesis

  28. Function Calls Examples • pow(3,2)calculates 32; evaluates to value of 9 • min(16/3,4)calculates minimum of 5⅓ & 4; evaluates to value of 4 • print( "Hi there!" )results in text saying Hi therebeing added to end of console

  29. Function Calls Examples • x = -6y = abs(x)Starts by assigning x a value of -6

  30. Function Calls Examples • x = -6y = abs(x)Starts by assigning x a value of -6Evaluates simple expression x; result of evaluation is value of -6

  31. Function Calls Examples • x = -6y = abs(x)Starts by assigning x a value of -6Evaluates simple expression x; result of evaluation is value of -6Uses -6as input to absolute value; result of evaluation is 6

  32. Function Calls Examples • x = -6y = abs(x)Starts by assigning x a value of -6Evaluates simple expression x; result of evaluation is value of -6Uses-6as input to absolute value; result of evaluation is 6Assigns y result of evaluating function call expression

  33. Function Calls Input toabs is NOTx x's valueinput to abs Examples • x = -6y = abs(x)Starts by assigning x a value of -6Evaluates simple expression x; result of evaluation is value of -6Uses-6as input to absolute value; result of evaluation is 6Assigns y result of evaluating function call expression

  34. Today's Plan Review Calling functions • Dr. Adrienne Decker repl.itDemo: function calls in Python

  35. Writing a Function Call Expression Subgoals • fc1) Write the function name • fc2) Write the argument lista) Start the argument list with an open parenthesisb) For each of function's input(s) in listed order, write the expression whose value is used for that inputc) Write a comma between each pair of argumentsd) End the argument list with a close parenthesis

  36. Pick the True Statement • Choose 1 statement which is true in Python: • Only variables have types • Variable can be assigned only once • str literals can use either double (") or single (') quotes • + performs addition if both subexpressions are numbers& catenation if at least 1 is a str

  37. Pick the True Statement Convince Your Neighbor Your Answer Is Correct • Choose 1 statement which is true in Python: • Only variables have types • Variable can be assigned only once • str literals can use either double (") or single (') quotes • + performs addition if both subexpressions are numbers& catenation if at least 1 is a str

  38. Pick the True Statement • Choose 1 statement which is true in Python: • Only variables have types • Variable can be assigned only once • str literals can use either double (") or single (') quotes • + performs addition if both subexpressions are numbers& catenation if at least 1 is a str

  39. Pick the True Statement • Choose 1 statement which is true in Python: • Only variables have types • Variable can be assigned only once • str literals can use either double (") or single (') quotes • + performs addition if both subexpressions are numbers& catenation if at least 1 is a str Only values have a type; • variable provides "name" for location holding value temporarily

  40. Pick the True Statement • Choose 1 statement which is true in Python: • Only variables have types • Variable can be assigned only once • str literals can use either double (") or single (') quotes • + performs addition if both subexpressions are numbers& catenation if at least 1 is a str Variables CAN be reassigned; • just replaces what it's value is

  41. Pick the True Statement • Choose 1 statement which is true in Python: • Only variables have types • Variable can be assigned only once • str literals can use either double (") or single (') quotes • + performs addition if both subexpressions are numbers& catenation if at least 1 is a str + does not combine a number & a string

  42. Pick the True Statement • Choose 1 statement which is true in Python: • Only variables have types • Variable can be assigned only once • str literals can use either double (") or single (') quotes • + performs addition if both subexpressions are numbers& catenation if at least 1 is a str ButCANNOT use both in same literal

  43. Today's Plan Review Calling functions Demo: function calls in Python

  44. Functions Python includes many built-in functions abs(num)min(num_1,num_2)max(num_1,num_2)pow(a_name,other_name)round(consistency_sucks)round(x,y)print(value_to_print)

  45. Imports Also has functions defined in modules Must importmodule to use these functions Example using Python's math module import math hope_close_enough = math.sin(3.141592) module_also_has_constants = math.pi/2 shorter = module_also_has_constants print( math.cos( shorter ) * 4 )

  46. Function Calls Examples • pow(3,2)calculates 32; evaluates to value of 9 • min(16/3,4)calculates minimum of 5⅓ & 4; evaluates to value of 4 • print( "Hi there!" )results in text saying Hi therebeing added to end of console

  47. Function Calls Input toabs is NOTx x's valueinput to abs Examples • x = -6y = abs(x)Starts by assigning x a value of -6Evaluates simple expression x; result of evaluation is value of -6Uses-6as input to absolute value; result of evaluation is 6Assigns y result of evaluating function call expression

  48. Function Calls Examples pow( 3 , 2 ) min( 16/3, 4 ) • print( "Hi there!" ) x = -6y = abs(x) fc1) Write the functionname

  49. Function Calls • Examples • pow( 3 , 2 ) • min( 16/3, 4 ) • print( "Hi there!" ) • x = -6y = abs(x) fc2a)Start argumentlistwithopen parenthesis

  50. Function Calls • Examples • pow(3 , 2 ) • min( 16/3, 4 ) • print("Hi there!" ) • x = -6y = abs(x) fc2b)Write expressionswhose values used for that input

More Related