Creating Functions with Parameters

Slides:



Advertisements
Similar presentations
Introduction to TouchDevelop
Advertisements

AP Computer Science Principles Data Abstraction and Procedural Abstraction Curriculum Module.
Graphics and Procedures Programming Right from the Start with Visual Basic.NET 1/e 5.
Introduction to TouchDevelop
Getting started with the turtle Find the latest version of this document at
Turtle Graphics Lesson 2 1. There are 3 homeworks to complete during the six lessons of this unit. Your teacher will let you know when a homework has.
Progression in KS3/4 Algorithms MONDAY 30 TH NOVEMBER SUE SENTANCE.
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
Today… Functions, Cont.: –Designing functions. –Functional Decomposition –Importing our own module –A demo: Functional solution to assignment 2. Winter.
JavaScript: API’s, Parameters and Creating Functions with Parameters
AP CSP: Creating Functions & Top-Down Design
Canvas and Arrays in Apps
Broadcasting (Adding a new level)
Vocabulary Algorithm - A precise sequence of instructions for processes that can be executed by a computer Low level programming language: A programming.
APIs and Function Parameters
Introduction to Event-Driven Programming
Do it now activity Last lesson we used Flowol to create a solution to a problem a computer could solve. Identify what each symbol does:
UNIT 2 – LESSON 4 Encoding Color Images.
Creating Functions with Parameters
Functions and Top-Down Design
Lesson 5-2 AP Computer Science Principles
UNIT 3 – LESSON 5 Creating Functions.
Check Your Assumptions
The Need for Programming Languages
The Need for Algorithms 2 days
APIs and Function Parameters
Looping and Random Numbers
Whole school homework projects
RAPID RESEARCH DATA INNOVATIONS
Lesson 9: "if-else-if" and Conditional Logic
Lesson 1: Buttons and Events – 12/18
LearnZillion Notes: --This is your hook. Start with a question to draw the student in. We want that student saying, “huh, how do you do X?” Try to be specific.
Lesson 10: Building an App: Color Sleuth
INTERMEDIATE PROGRAMMING Lesson
Learning to program with Logo
Frozen Graphics Lesson 3.
Microsoft Word Reviewing Documents.
INTERMEDIATE PROGRAMMING LESSON
For example, what is ? LearnZillion Notes:
Graph Paper Programming
Creativity in Algorithms
Lesson 17: Building an App: Canvas Painter
LESSON 14 - Building an App: Image Scroller
Graph Paper Programming
Log onto a computer first then ….
LESSON 13 – INTRO TO ARRAYS
UNIT 3 CHAPTER 1 LESSON 4 Using Simple Commands.
CISC101 Reminders Assn 3 due Friday, this week. Quiz 3 next week.
An Introduction to VEX IQ Programming with Modkit
HAPPY NEW YEAR! Lesson 7: If-statements unplugged
Looping and Random Numbers
Unit 3: Lesson 9-Looping and Random Numbers
Unit 3: Lesson 6 & 7- Functions and Top-Down Design / APIs and Function Parameters Day 27.
Computational Thinking for KS3
An Introduction to VEX IQ Programming with Modkit
Transformations – Day 3 Rotations.
Game Loop Update & Draw.
RAPID RESEARCH DATA INNOVATIONS
Rapid Research - Format Showdown
Functions and Top-Down Design
Explain what touch develop is to your students:
INTERMEDIATE PROGRAMMING LESSON
Lesson 8: Creating Functions with Parameters
TRANSITION TO SECONDARY SCHOOL
Loops and Switches How Do You Make Loops and Switches? lesson > TeachEngineering.org Center for Computational Neurobiology, University of Missouri.
Quiz: Computational Thinking
U3L8 Creating Functions with Parameters
I wonder…2 _ 1 2 ? LearnZillion Notes:
U3L4 Using Simple Commands
Presentation transcript:

Creating Functions with Parameters UNIT 3 – LESSON 8 Creating Functions with Parameters

VOCABULARY Parameter - An extra piece of information passed to a function to customize it for a specific need Comments – explanations programmers write into their code to explain their thinking to a human reader. Does not affect the run of the program Random Numbers – ((High – Low) + 1) * Rnd() ) + Low) a way of computer generating numbers that seem to be random for purposes of programming problems

The purpose of this lesson is to practice using and creating functions with parameters. You will learn that writing functions with parameters can generalize solutions to problems even further. We will also be using the Random Generator.

The basic idea is that 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 realize that you basically need a duplicate of some code you’ve already got, but you just want to change some numbers. 

We learned to use a lot of new turtle commands 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 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

New Code to Use!

Comments

Parameters allow the creation of a generalized solution to a whole class of problems, rather than individually solving many specific problems. Parameters remove the need to create repetitive functions, making code easier to write, read, and change.

Whenever you have two functions that basically do the same thing make a function with a parameter instead, to remove the need to duplicate code. If you need a function to do the same thing a lot of different ways, then use a parameter so one function can do it right away.

Let’s open up Code Studio Let’s open up Code Studio. You will do these things: Watch a 5 minute video on parameters Practice drawing shapes Define a parameter #7 Use comments in your code Use multiple parameters in your Under the Sea drawing – see next slide)

Show me this (#15):

Check this (#17) keep adding to your drawing

Check #18 in Code Studio (like AP portfolio piece!):

Do your assessments and reflections in Code Studio Do your assessments and reflections in Code Studio. I will check on screen: 15, 17 I will check on Code Studio: 18 Homework is to finish #18