0% found this document useful (0 votes)
17 views3 pages

T5 Worksheet 5

The document is a worksheet focused on procedures and functions in programming, containing tasks that involve defining and analyzing functions and procedures. It includes questions about parameter counts, output from function calls, and writing functions for specific tasks like input validation and summing integers. Additionally, it addresses error identification in pseudocode related to calculating the area of a triangle.

Uploaded by

itssaara09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

T5 Worksheet 5

The document is a worksheet focused on procedures and functions in programming, containing tasks that involve defining and analyzing functions and procedures. It includes questions about parameter counts, output from function calls, and writing functions for specific tasks like input validation and summing integers. Additionally, it addresses error identification in pseudocode related to calculating the area of a triangle.

Uploaded by

itssaara09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Worksheet 5 Procedures and functions

Unit 7 Programming

Name:...................................................................................................... Class: ......................

Task 1
(a) How many parameters does procedure printInfo have?
procedure printInfo(firstname, surname, age)
fullName = firstname + " " + surname
years = str(age) + " years old."
print(fullName)
print(years)
endprocedure

(b) What will be printed by the following call to the procedure?


printInfo("Mickey", "Mouse", 92)

Task 2
Write a function called answerYorN to input and check the response to a question. It should be
“y” or “n”. Any other response is invalid, and the function should ask the user to re-enter until a
valid response is received. The function will then return “y” or “n” when a valid response is
received.
The subroutine is called as follows:
response = answerYorN()

1
Worksheet 5 Procedures and functions
Unit 7 Programming

Task 3
Write a function called addIntegers which takes two integers. The function needs to add up all
the numbers between the first number and last number and return the result.
For example addIntegers(5,10) will return 45

Task 4
1. (a) What is printed out when the following program is run?

function calculateTotal(prices)
total = 0
for i = 0 to prices.length
total = total + prices[i]
next i
return total
endfunction

quantity = 5
itemPrices = [2.00, 2.50, 1.00, 1.00, 1.00]
totalPrice = calculatePrice(itemPrices)
print(totalPrice)

2
Worksheet 5 Procedures and functions
Unit 7 Programming

(b) Name two local variables used inside the calculateTotal function. What is the scope of
each of these variables?

2. Examine the following pseudocode.


function triangle(base, height)
halfBase = base / 2
area = halfbase * height
endfunction

#main program
area = triangle(8, 10)
print(area)

The pseudocode contains an error.


Find the error and write a line of code to fix it.

You might also like