U3L8 Creating Functions with Parameters

Slides:



Advertisements
Similar presentations
Introduction to TouchDevelop
Advertisements

CS Unplugged Demo Lester Jackson, Sr. Program Manager.
Coupling and Cohesion Pfleeger, S., Software Engineering Theory and Practice. Prentice Hall, 2001.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
By the end of this session you should be able to...
Introduction to TouchDevelop
Cohesion and Coupling CS 4311
Getting started with the turtle Find the latest version of this document at
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
JavaScript: API’s, Parameters and Creating Functions with Parameters
JavaScript/ App Lab Programming:
5.04 Apply Decision Making Structures
Canvas and Arrays in Apps
VEX IQ Curriculum Smart Machines Lesson 09 Lesson Materials:
User-Written Functions
Vocabulary Algorithm - A precise sequence of instructions for processes that can be executed by a computer Low level programming language: A programming.
Building Java Programs
APIs and Function Parameters
Unit 5 Lesson 3: Introduction to Arrays
Lesson Objectives Aims From the spec:
Introduction to Event-Driven Programming
Structures, Strategies and Compositions
Creating Functions with Parameters
Functions and Top-Down Design
Creativity in Algorithms
UNIT 3 – LESSON 5 Creating Functions.
Lecture 25 More Synchronized Data and Producer/Consumer Relationship
The Need for Programming Languages
APIs and Function Parameters
Functions CIS 40 – Introduction to Programming in Python
Looping and Random Numbers
Vocabulary Algorithm - A precise sequence of instructions for processes that can be executed by a computer.
Functions.
Lesson 9: "if-else-if" and Conditional Logic
Lesson 1: Buttons and Events – 12/18
INTERMEDIATE PROGRAMMING Lesson
Exceptions C++ Interlude 3
Learning to program with Logo
Frozen Graphics Lesson 3.
INTERMEDIATE PROGRAMMING LESSON
Loops and Switches Pre-Quiz
More Selections BIS1523 – Lecture 9.
Lesson 8: Boolean Expressions and "if" Statements
Graph Paper Programming
Creativity in Algorithms
Program Design Introduction to Computer Programming By:
Formatting Paragraphs
Graph Paper Programming
Lesson 16: Functions with Return Values
INTERMEDIATE PROGRAMMING LESSON
LESSON 13 – INTRO TO ARRAYS
UNIT 3 CHAPTER 1 LESSON 4 Using Simple Commands.
Creating Functions with Parameters
HAPPY NEW YEAR! Lesson 7: If-statements unplugged
Looping and Random Numbers
Unit 3: Lesson 6 & 7- Functions and Top-Down Design / APIs and Function Parameters Day 27.
Computational Thinking for KS3
CS 1111 Introduction to Programming Fall 2018
Game Loop Update & Draw.
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
INTERMEDIATE PROGRAMMING LESSON
Lesson 8: Creating Functions with Parameters
U3L1 The Need For Programming
Vocabulary Algorithm - A precise sequence of instructions for processes that can be executed by a computer Low level programming language: A programming.
Loops and Switches How Do You Make Loops and Switches? lesson > TeachEngineering.org Center for Computational Neurobiology, University of Missouri.
Review of Previous Lesson
ECE 352 Digital System Fundamentals
U3L2 The Need For Algorithms
U3L4 Using Simple Commands
Parameters and Arguments
Presentation transcript:

U3L8 Creating Functions with Parameters CS Principles U3L8 Creating Functions with Parameters

U3L8 Creating Functions with Parameters Objectives SWBAT: Write functions with parameters to generalize a solution instead of duplicating code. Identify appropriate situations for creating a function with parameters. Use random numbers as inputs to function calls for the purpose of testing. Add parameters to a function in an existing piece of code to generalize its behavior.

U3L8 Content: Creating Functions with Parameters You often want to write a function that takes some input and performs some action based on that input. For example, the turtle function moveForward is much more useful when you can specify how much to move forward (e.g., moveForward(100)), rather than just a fixed amount every time. It’s very common to encounter situations where as a programmer you need a duplicate of some code, but you just want to change some numbers. That’s a good time to write a function with a parameter; the parameter just acts as a placeholder for some value that you plug in at the time you call the function. It’s considered good practice to give descriptive names to your functions; the same is true for the names of the parameters themselves. For example: drawSquare(sideLength) is better than drawSquare(stuff).

U3L8 Vocabulary Parameter - An extra piece of information that you pass to the function to customize it for a specific need. randomNumber(min, max) – Function that returns a random number in the closed range from min to max. Define a function - When you define a function you give a name to a set of actions you want the computer to perform.  Call a function - When you call a function you are telling the computer to run (or execute) that set of actions. When you call a function with parameters you must match the order of parameters in the function definition. Define a function with parameters: Gives a name to a set of parameter driven actions you want the computer to perform, and optionally return a value. Some functions take parameter values as input to be able to abstract multiple different actions.

U3L8 Stage 1 Clink on the links in U3L8 Stage 1 in the New Blocks section and read the explanations and examples before beginning work on code studio. Random Number min/max: https://docs.code.org/applab/randomNumber_min_max/ Call a function with parameters: https://docs.code.org/applab/callMyFunction_n/ Define a function with parameters: https://docs.code.org/applab/functionParams_n/

U3L8 Video (stage 2) and Code Studio In the previous lesson, we learned to use a lot of new turtle commands. Some of these commands accept a parameter, or even many parameters, which allow us to pass values to the function. This allowed us to make much more interesting images by specifying precisely how far the turtle should move or turn, and introduced the ability to choose specific pen sizes and colors. Parameters are a powerful programming construct. Suppose we have a whole group of similar problems, like turning the turtle some amount. Without a parameter we would need 360 different functions, one for each number of degrees we wanted to turn! Parameters allow us to use a single function as a general solution to a whole group of problems. This is clearly a useful construct to use in our programs, and in today’s lesson we’re going to learn how to create functions with parameters for ourselves. Watch the video in U3L8 Code Studio Stage 2, and complete the rest of code studio stages 3-20.

U3L8 Prompt Prompt: “Develop a rule for deciding when to create a function with a parameter rather than a normal function. Below your rule write a couple sentences justifying your rule.“