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.

The Notes:

Procedures can be called methods or functions. procedure call interupts statments to run procedure before you write:

  • know what arguments you need
  • be ble to call the procedure to call a procedure write the name of the procedure followed by parenthesis containing the paramaters
  1. name procedure
  2. what apramater are needed
  3. what data is needed to acomplish my goal
  4. do I want numerical value or complete an action ## What are procedures?

Fill in the blanks please:

Procedure: a named group of instructions that have paramaters and return values

Parameters: input values of a procedure

Arguments: specify values of the paramaters when the procedure is called

Modularity: An splitting large procedures into smaller ones with more uses

Procedural Abstraction: name for a process that allow a procedure to be used by only knowing what it does

Return: sends the output of the procedure to where it was called

What are some other names for procedures?: functions and actions (maybe)

Why are procedures effective?: procedures make code more eficcient by making it so you dont have to write the same code every time.

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

decimal = 35775
def convertToBinary(n):
    thelist = []
    while n > 0:
        if n % 2 == 0:
            thelist.append(0)
            n = n / 2
        else:
            thelist.append(1)
            n = n / 2
            n = n - 0.5
    x = len(thelist) - 1
    final = str(thelist[x])
    x = x - 1
    while x >= 0:
        final = final + str(thelist[x])
        x = x - 1
    print(final)

convertToBinary(decimal)
1000101110111111

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)

values = [2,5,3,6,86,253,4325,78,53,69,23,4142,56373,420]
def findextrema(set):
    min = 0
    max = 0
    if set[0] > set[1]:
        max = set[0]
    else:
        min = set[0]
    for i in range(len(set)):
        if set[i] > max:
            max = set[i]
        elif set[i] < min:
            max = set[i]
    return[min,max]

stuff = findextrema(values)
print('min is',stuff[0],'- max is',stuff[1])
min is 2 - max is 56373

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 BinaryS2L(binary):
    if type(binary) == str:
        out = []
        i = len(binary) - 1
        while i >= 0:
            out.append(int(binary[i]))
            i = i - 1
        out.append(0)
        return(out)
    elif type(binary) == list:
        out = ''
        for i in range(len(binary)):
            out = str(binary[i]) + out
        return(out)

def BinaryAdder(x,y):
    one = BinaryS2L(x)
    print(one)
    two = BinaryS2L(y)
    print(two)
    temp = 0
    end = []
    rng = len(x) + 1
    for i in range(rng):
        if one[i] + two[i] + temp == 0:
            temp = 0
            end.append(0)
        elif one[i] + two[i] + temp == 1:
            temp = 0
            end.append(1)
        elif one[i] + two[i] + temp == 2:
            temp = 1
            end.append(0)
        elif one[i] + two[i] + temp == 3:
            temp = 1
            end.append(1)      
    return(BinaryS2L(end))
            

a = str(input('What is the first of the two numbers would you like to add? Please be sure that both values are the same binary length.'))
b = str(input('What is the second of the two numbers would you like to add? Please be sure that both values are the same binary length.'))
print(BinaryAdder(a,b))

# The output shown below is the output you are supposed to get
[0, 1, 0, 0]
[1, 0, 1, 0]
0111