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: is a named group of programming instructions that may have parameters and return values.

Parameters: are 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: rovides 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?: method or function depending on the language

Why are procedures effective?: We have the ability to alter the result without actually changing the calls to the program

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

decimal = 7
def convertToBinary(n):
    bin = ""
    i = 7
    while i >= 0:
        if n % (2**i) == n:
            bin = bin + "0"
            i -= 1
        else:
            bin = bin + "1"
            n -= 2**i
            i -= 1
    print(bin)
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)

num1 = 6
num2 = 7

function findMax(numberA, numberB) {
    if (numberA > numberB) {
        console.log(numberA + " is max")
    } else {
        console.log(numberB + " is max")
    }
}

function findMin(numberA, numberB) {
    if (numberA < numberB) {
        console.log(numberA + " is min")
    } else {
        console.log(numberB + " is min")
    }
}

findMax(num1, num2)
findMin(num1,num2)
  Input In [7]
    function findMax(numberA, numberB) {
             ^
SyntaxError: invalid syntax

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.

string = "APCSP"
up = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
low = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
declist = []
binlist = []

def charToBinary(x):

    for y in up:
        if x == y:
            declist.append((up.index(x)) + 65)
    
    for z in low:
        if x == z:
            declist.append((low.index(x)) + 97)
    
def convert(dec):
    bin = ""
    i = 7

    while i >= 0:
        if dec % (2**i) == dec:
            bin = bin + "0"
            i -= 1
        else:
            bin = bin + "1"
            dec -= 2**i
            i -= 1

    binlist.append(bin)


for ch1 in string:
    charToBinary(ch1)

for decimal in declist:
    convert(decimal)

print(binlist)
    
['01000001', '01010000', '01000011', '01010011', '01010000']