
Subroutines
Presentation
•
Computers
•
10th Grade
•
Medium
Roy Duguid
Used 20+ times
FREE Resource
14 Slides • 11 Questions
1
Do Now:
Teams > Coding > Subroutines > Do Now
2
# Length: Find number of characters in a string print(len("hello world"))
# Output: 11
# Case Conversion text = "hello world" print(text.upper()) # UPPERCASE -> HELLO WORLD print(text.title())
# Title Case -> Hello World
# Slicing word = "computer" print(word[0:3])
# Output: com
# Substring Search print("cat" in "concatenate")
# Output: True
# Find Position print("banana".find("a")) # Output: 1
3
Big Question
How do we define a subroutine?
How do we describe the purpose of parameters in subroutines?
How do we use procedures that accept arguments through parameters?
Key words: subroutine, function, procedure, parameter, argument
4
Sub programs are used to avoid unnecessary code duplication in
programs and to make programs easier to read.
Sub Programs
© ZigZag Education, 2020
Procedures
A sub program is a section of code that performs a specific task and
can be called when needed at any point in the program.
There are two different types of sub program:
Functions
5
A procedure is a sub program that doesn’t return a value back
to the main program.
Procedures
© ZigZag Education, 2020
def message():
print("Computer")
print("Science")
print("Rocks")
message()
This is an example procedure that will output the text "Computer",
"Science", "Rocks" whenever it is called.
A procedure or function won’t run unless it is called.
Output
Computer
Science
Rocks
Procedure call
6
Sometimes procedures and functions need data in order to carry out
their job. This is where parameters come in.
Parameters
© ZigZag Education, 2020
def areaCalc(width,height):
area = width * height
print(area)
areaCalc(10,5)
Parameters are like placeholders for values that a procedure or
function expects to be passed when it is called.
In this example the values 10 and 5 are passed into the Width and
Height parameters when the areaCalc procedure is called.
Output
50
Parameters
width
10
height
5
area
50
7
A function is a sub program that returns a value to the main program.
Functions
© ZigZag Education, 2020
def areaCalc(width,height):
area = width * height
return area
print(areaCalc(10,5))
The returned value takes the place of the original function call in the
main program.
This is the areaCalc sub program written as a function.
Output
50
width
10
height
5
area
50
8
Where a variable can be accessed within a program depends on the
variable scope. There are two types of variable:
VariableScope
© ZigZag Education, 2020
def speedCalc(distance, time)
speed = distance / time
return speed
answer = speedCalc(90, 2)
Local
Declared within a sub program and only accessible within
that sub program.
Global
Declared outside any sub programs and accessible
throughout the program, including inside sub programs.
Local Variable
Global Variable
This example
program features
a procedure to
calculate speed.
It uses both a
local and a global
variable.
Global
Local
9
10
11
12
13
Questions ahead....
14
Multiple Choice
Which of the following is not an example of a subroutine?
Procedure
Function
List
15
Multiple Select
What is the purpose of using subroutines in your programming? (select more than 1)
Avoiding repeated sections of code
Making your code shorter and easier to read
Enabling you to split your code into sections
Avoiding making errors in your code
16
Multiple Choice
What is the name of the subroutine?
happyBirthday
person
def
17
Multiple Choice
What is the name of the parameter?
happyBirthday
person
def
18
Multiple Choice
What is the name of the subroutine?
addNumbers
num1
num2
total
19
Multiple Choice
num1 and num2 are the parameters
True
False
20
Multiple Choice
Which subroutine will return a value back to the program?
Procedure
Function
21
Multiple Choice
Which subroutine will not return a value back to the program?
Procedure
Function
22
Multiple Choice
A procedure can return a value to be used later in the program
True
False
23
Multiple Choice
A function can return a value to be used later in the program
True
False
24
Multiple Choice
What is the name of the subroutine?
username
firstName
secondName
25
Activity 1
Do Now:
Teams > Coding > Subroutines > Do Now
Show answer
Auto Play
Slide 1 / 25
SLIDE
Similar Resources on Wayground
22 questions
Perkembangan pernagkat lunak
Presentation
•
10th Grade
17 questions
Algoritma
Presentation
•
10th Grade
20 questions
ekonomi kelas X
Presentation
•
10th Grade
20 questions
Basic Python Review Lesson
Presentation
•
9th Grade
20 questions
MS DOS
Presentation
•
8th Grade
17 questions
American History World War II
Presentation
•
10th Grade
17 questions
PENGENALAN APLIKASI PRESENTASI POWER POINT
Presentation
•
10th Grade
21 questions
Input Output Variabel Program C
Presentation
•
10th Grade
Popular Resources on Wayground
6 questions
Secondary Safety Quiz
Presentation
•
9th - 12th Grade
10 questions
Afterschool Activities & Sports
Quiz
•
6th - 8th Grade
19 questions
ROAR Week 2026
Quiz
•
9th - 12th Grade
20 questions
Lab Safety Quiz
Quiz
•
6th Grade
15 questions
Cool Tool:Chromebook
Quiz
•
6th - 8th Grade
22 questions
would you rather
Quiz
•
3rd - 11th Grade
21 questions
Continents and Oceans
Quiz
•
6th Grade
20 questions
Parts of Speech
Quiz
•
5th Grade
Discover more resources for Computers
20 questions
Early Computing
Quiz
•
7th - 12th Grade
10 questions
Exploring the Parts of a Computer
Interactive video
•
6th - 10th Grade
10 questions
Navigating Digital Citizenship and Online Safety
Interactive video
•
6th - 10th Grade
10 questions
Mastering Proper Keyboarding Techniques
Interactive video
•
6th - 10th Grade