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 algorithm that has parameters and return values

Parameters: inputs of a procedure

Arguments: specifying values of parameter when procedure is called

Modularity: Seperating parts of functions into other functions for easier usage

Procedural Abstraction: The ability to call a process without stating what it does, but the name of the procedure

What are some other names for procedures?: method, function

Why are procedures effective?: They can do certain things without stating the same thing many times in different places

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

decimal = 7

def convertToBinary(n):
    ans = ""
    if n == 0:
        return 0
    while n:
        ans += str(n&1)
        n = n >> 1
     
    ans = ans[::-1]
 
    return ans
print(convertToBinary(decimal))
111

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)

def findMax(*args):
    ans=args[0]
    for arg in args:
        if ans<arg:
            ans=arg
    return ans
def findMin(*args):
    ans=args[0]
    for arg in args:
        if ans>arg:
            ans=arg
    return ans
print(findMax(1,3,4,5,2,6))
print(findMin(1,3,4,5,2,6))
6
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.

def charToBinary(x):
    ans=[]
    for chr in x:
        dec=ord(chr)
        ans.append(convertToBinary(dec))
    return ans

string="APCSP"
print(string+" in binary is")
print(charToBinary(string))
# The output shown below is the output you are supposed to get
# ''APCSP'' in binary is 
# [1000001, 1010000, 1000011, 1010011, 1010000]
APCSP in binary is
['1000001', '1010000', '1000011', '1010011', '1010000']