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?

Fill in the blanks please:

Procedure: A named group of programming instructions that have parameters and return values. A procedure call will interrupt a series of statements and instead execute the code within the procedure. It will return to the original program call after the procedure hs been fully executed.

Parameters: input values of a procedure

Arguments: the values of the parameters when a procedure is called.

Modularity: Separating a program's function into independent pieces or blocks while containing all o the parts needed to execute a single aspect.

Procedural Abstraction: Provides a name for a process that allows a procedure to be used.

What are some other names for procedures?: functions

Why are procedures effective?: Procedures are effective in that they allow for simplification and reusability of code. Each piece of code in the program is now more meaningful as some higher level process are simplified or abstracted down into simple procedures.

Challenge 1 below: Add the command that will call the procedure.

decimal = 7

def convertToBinary(decimal):
    N = 7
    res = ""
    while N >= 0:
        if (decimal - 2**N) >= 0:
            res = res +"1"
            decimal -= 2**N
            N-=1
        else:
            N-=1
            res = res + "0"
    return res

print(convertToBinary(decimal))
00000111

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)

function findMax (numA, numB) {
    return numA > numB ? numA : numB;
}

function findMin (numA, numB) {
    return numA < numB ? numA : numB;
}

Above is the code in javascript, but the code wouldn't run in the notebook, I've attached the result in an online debugger and compiler below.

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 stringToBinary(x):
    res = [convertToBinary(ord(i)) for i in x]

    return res

print("Binary representation of APCSP")
print(stringToBinary("APCSP"))
Binary representation of APCSP
['01000001', '01010000', '01000011', '01010011', '01010000']