Important Vocab!

Procedure: A named group of programming instructions that can have parameters and returning values.

Parameters: Inputs values of a procedure that limites it and allows certain values.

Arguments: Values of the parameters that are in motion when the procedure is called apond.

Modularity: The process of separating a function into its own pieces, each of them containing all the parts needed to execute a single part of the functionality.

Procedural Abstraction: An abstraction that provides a name for a process that makes it so a procedure can be used only knowing what it does and not how it does it.

Questions!

What are some other names for procedures?:

Processes or Functions.

Why are procedures effective?:

Procedures are effective because they have the ability to change the result of a piece of code without actually changing the calls to the program. This is effective because it is easier than going into a function and changing different variables and sub functions and risk causes errors.

Additional Notes!

Procedure can or can no return a value. Values include numbers and booleans. Procedure works similarly to a function. Defining the procedure calls it along with setting its parameters. Parameter is the value(s) that would be used in the procedure to determine the output. Procedures have the ability to change the result without changing the calls to the program.

In java, you call a prodecure by defining its function. Defining the function allows values to change the parameters, resulting in a new outcome. Those new values are normally inputed by the coder in the code, not in a input, but it can be.

Procedural Abstraction provides a name for a process that makes it so a procedure can be used knowing what it does. Kind of like defining a function. This allows the code to use the procedure in different situations.

Modularity is used to help identiy any sort of issues that arise in the code. It breaks down the code, making the error easier to see.

Challenge 1:

Add the command that will call the procedure.

decimal = 7

def convertToBinary(n):
    return bin(n)
print(convertToBinary(decimal))
0b111

Challenge 2:

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(numberA, numberB):
    if numberA > numberB:
        print("Max: " + str(numberA))
    elif numberA < numberB:
        print("Max: " + str(numberB))
    else:
        print("Max: " + str(numberA) + " numberA and numberB are equal")

def findMin(numberA, numberB):
    if numberA < numberB:
        print("Min: " + str(numberA))
    elif numberA > numberB:
        print("Min: " + str(numberB))
    else:
        print("Min: " + str(numberA) + " numberA and numberB are equal")

findMax(3, 4)
findMin(3, 4)

#Call both functions so that the parameters numberA and numberB are given a value.

#Optional bonus- create a procedure that can determine the minimum or maximum value out of more than two parameters.
Max: 4
Min: 3

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):
    binary = []
    decimal = []
    for i in x:
        decimal.append(ord(i))  # ord converts characters to ASCII decimal
    for i in decimal:
        binary.append(int(bin(i)[2:]))  # bin converts deciaml to binary
    return binary

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

xlist = "Lucas Moore 16"
result = charToBinary(xlist)
print(xlist + " in binary is")
print(result)
APCSP in binary is
[1000001, 1010000, 1000011, 1010011, 1010000]
Lucas Moore 16 in binary is
[1001100, 1110101, 1100011, 1100001, 1110011, 100000, 1001101, 1101111, 1101111, 1110010, 1100101, 100000, 110001, 110110]