Unit 3.12 and 3.13 Calling and Developing Procedures Notes
- Take some additional notes that you would like here for 3.12 and 3.13. We will be looking for additional notes from the presentation.
- What are procedures?
- Challenge 1 below: Add the command that will call the procedure.
- Challenge 2 below: Complete the Min and Max procedure in either JavaScript and Python using the instructions from the JavaScript page. (JavaScript will get you a extra 0.1)
- Homework/Hacks: For the hw, you have two options, easy or hard. The easy hack is for a 2.7 + extra work for the full 3. The easy hack is simply creating your own procedure with your own creativity. Since there is a lot of leeway for this one, you must do additional work to get a 3. For the hard hack, below is the start to a character to binary convertor. This is just a template, but the goal is to translate "APCSP" into binary. You can delete the existing code if you want. The only contraint is that you must use a procedure. Doing this will get you a 3.
What are procedures?
Fill in the blanks please:
-
Procedure: A named group of programming instructions that may have parameters and return values
-
Parameters: The input values of a procedure
-
Arguments: Specify the values of the parameters when a procedure is called
-
Modularity: Separating a program's functions into independent pieces or blocks, each containing all the parts needed to execute a single aspect of the functionality
-
Procedural Abstraction: provides a name for a process that allows a procedure to be used only knowing WHAT it does, not HOW it does it
-
What are some other names for procedures?: A procedure is also known as a function, you can name the function whatever you want
-
Why are procedures effective?: We have the ability to alter the result without actually changing the calls to the program
decimal = 7
binary = format(decimal, 'b') # procedure that converts to binary
# Print the result
print(binary)
// Start by creating a procedure called findMax and set the parameters to numberA and numberB.
function findMax(numberA, numberB){
// Within the procedure, write the code to determine which of the two parameters, numberA or numberB, is the larger value. Print that value.
if (numberA > numberB){
console.log(numberA)
}
else{
console.log(numberB)
}
}
findMax(20, 40)
// Repeat the process, this time creating a procedure called findMin, which will print the parameter with a smaller value.
function findMin(numberA, numberB){
if (numberA < numberB){
console.log(numberA)
}
else{
console.log(numberB)
}
}
findMin(20, 40)
// Call both functions so that the parameters numberA and numberB are given a value.
var numberA = 1;
var numberB = 2;
console.log(findMax(numberA, numberB));
console.log(findMin(numberA, numberB));
// Optional bonus- create a procedure that can determine the minimum or maximum value out of more than two parameters.
Homework/Hacks: For the hw, you have two options, easy or hard. The easy hack is for a 2.7 + extra work for the full 3. The easy hack is simply creating your own procedure with your own creativity. Since there is a lot of leeway for this one, you must do additional work to get a 3. For the hard hack, below is the start to a character to binary convertor. This is just a template, but the goal is to translate "APCSP" into binary. You can delete the existing code if you want. The only contraint is that you must use a procedure. Doing this will get you a 3.
def charToBinary(x):()
# The output shown below is the output you are supposed to get
def charToBinary(x):
# Get the ASCII code of the characters in the string
ascii_code = ord(x)
# Convert the ASCII code to binary (string of 0 and 1)
binary = bin(ascii_code)
# Remove the "0b" from the binary string
binary = binary[2:]
# 8 digits
binary = binary.zfill(8)
return binary
# Test the function
string = "APCSP"
for x in string:
binary = charToBinary(x)
print(str(x) + " : " + str(binary)) #formatting for the printed output