Unit 7 – Lesson 2 Parameters and Return Investigate
16 Slides717.58 KB
Unit 7 - Lesson 2 Parameters and Return Investigate
Unit 7 Lesson 2 - Warm Up Prompt: Are clean and organized programs more useful for computers or people? Why? Try to give examples from
Unit 7 Lesson 2 - Activity Review Functions with parameters and return values help us simplify our code Functions can only return one value at a time A function can have: No parameters and no return values Parameters, but no return values Return values, but no parameters Parameters and return values
Unit 7 Lesson 2 - Activity Do This: Find a partner Navigate to Level 2 Read the program with your partner Respond to all the questions for your app Be ready to share your responses and what you learned with the class.
Unit 7 Lesson 2 - Activity Discuss as a class: How does calculate(symbol) work? What is the parameter? What is the argument? What is returned?
Unit 7 Lesson 2 - Activity Do This: Look at lines 30-36. Discuss with a partner how the MOD operator % works.
Unit 7 Lesson 2 - Activity MOD Add 3 2 5 Subtract 3-2 1 Multiply 3*2 6 Divide 3/2 1.5 MOD 3%2 1 MOD is the remainder that is left after a number is divided by another number
Unit 7 Lesson 2 - Activity Let's Practice the answer 17 % 5 5 3 17 152 remainder 2
Unit 7 Lesson 2 - Activity When is this useful? A common usage is to determine if a number is even or odd. If you divide any number by two and there is no remainder, the number is even! You can use MOD to determine if a number is divisible by another number.
Unit 7 Lesson 2 - Activity Do This: With your partner: Navigate to Level 3 Read lines 1-14 What is happening here? Be prepared to discuss as a class.
Unit 7 Lesson 2 - Activity Do This: Now, read the function on lines 15-34 carefully. After you are done, explain to your partner how the function works, what parameters it takes and what is returned. Extra time? Complete the modify.
Unit 7 Lesson 2 - Activity Discuss as a class: How does the Word Game Helper work?
Unit 7 Lesson 2 - Wrap Up Takeaways: Extracting shared features to generalize functionality is known as procedural abstraction. Using parameters allows the functions (also called procedures) to be generalized. Using procedural abstraction helps improve code readability. Procedural abstraction manages complexity by allowing for code reuse. For example: the function move(id, direction) could be used to move an element in any direction, rather than writing separate functions for each direction.