Lab 5.1- Functions and Pseudocode Yoa bave been coding with modules in pseudocod
ID: 3595043 • Letter: L
Question
Lab 5.1- Functions and Pseudocode Yoa bave been coding with modules in pseudocode and functions when using Python. Yon modules in pseudocode can be made into functions by returning a value A fnction is a special type of module that retums a value back to the part of the program hat called it Most programming languages provide a library of prewritten functions that performm commonly needed tasks. Library fmctions are built into the programming language and you can call them as needed. They are commonly performed tasks. Help Video: lab5-1.wmv Writing Your Own Function that Returns an Integer Step 1: Afunction contains three parts: a header, a body, and a rethurn statement The first is a function beader which specifies the data type of the value that is to be returned, the name of the function, and any parameter variables used by the function to accept arguments. The body is comprised of one or more statements that are executed when the fumction is called In the following space, complete the following: (Reference: Writing Your Own Functions, page 236). a. Write a fimction with the header named adden. b. The finction will accept an Integer variable named mumber. C. The finction body will ask the user to enter a mumber and then add 10 to the umber. The answer will be stored in the variable mber d. The retum statement will retum the value of number. Function a Display "Enter number Input c number + 10 Return d End FunctionExplanation / Answer
1.
Step 1
Function addTen(Integer number)
Input number
number = number + 10
Return number
End Function
Step 2
Set number = addTen(number)
2.
Step 1
Function gender(Boolean answer)
Declare String type
Display "Enter your gender (male or female) : "
Input type
If (type == "male") Then
answer = False
Else
answer = True
EndIf
Return answer
End Function
Step 2:
Set answer = gender(answer)
3.
Step 1:
Declare Integer myNumber
Declare Real squareRoot
Display "Enter a number:"
Input myNumber
Set squareRoot = sqrt(myNumber)
Display "The square root is", squareRoot
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.