Functions and Methods in Programming

Functions and Methods in Programming
1 / 12
next
Slide 1: Slide
Computer Science

This lesson contains 12 slides, with interactive quizzes and text slides.

time-iconLesson duration is: 45 min

Items in this lesson

Functions and Methods in Programming

Slide 1 - Slide

What is a Function?
A Function is a REUSABLE block of code that performs a specific task. Functions can take arguments and can return values, but neither is required.

Slide 2 - Slide

Why do we use functions?
To make code shorter
To reuse instructions
To confuse the computer
To avoid variables

Slide 3 - Poll

Parts of a Function
Name - Label to call the function
Arguments - Variables that are passed into the function
Body - Steps to follow
Return - The output or result of the function

Slide 4 - Slide

Can you think of something you do every day that could be a function?

Slide 5 - Open question

Slide 6 - Slide

Practice
Create a function called Greetings. Greetings takes one argument and returns a greeting using the name.

Create a function called Add that takes two numbers ("a" and "b"). Return the value of a + b

Slide 7 - Slide

What is a function in coding?
A
A type of variable
B
A reusable block of code
C
An error in code
D
A data structure

Slide 8 - Quiz

What are arguments in a function?
A
Local variables
B
Values passed to a function
C
Function names
D
Return values

Slide 9 - Quiz

What does a return statement do?
A
Exits a function and gives output
B
Calls another function
C
Creates a loop
D
Defines a function

Slide 10 - Quiz

Can a function have multiple arguments?
A
Only numbers as arguments
B
Yes, it can have many arguments
C
No, only one argument allowed
D
Only strings as arguments

Slide 11 - Quiz

What is a method in coding?
A
A function associated with an object
B
A type of loop
C
A variable type
D
An error handler

Slide 12 - Quiz