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 may have parameters and return values; can also be referred as method or function, depending on the language.

Parameters: 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 blocks that work together to allow a program to function

Procedural Abstraction: The name for a process that allows a procedure to be used while only knowing what it does, and not how the program executes the procedure

What are some other names for procedures?: Processes, operations, modules

Why are procedures effective?: Procedures are effective because they allow for code to be more organized while still retaining functionality

Additional Notes:

  • Procedures interrupt a series of statements and makes the program execute the procedure instead
  • The original code will be run after the procedure is executed
  • Procedures may or may not return values (such as numbers or booleans)
  • Procedures need names to be called (Ex: 'convertDecimalToBinary' for a decimal to binary converter)
  • Procedures allow for additional cells outside of code to be changed without having to change the code itself

Challenge 1 below:

Add the command that will call the procedure.

decimal = 7

def convertToBinary(decimal):
    divValue = decimal
    remainder = 1
    finalBin = ''
    while divValue > 0:
        remainder = divValue % 2
        divValue = (int)(divValue / 2)
        finalBin = str(remainder) + finalBin
    return finalBin

binary = convertToBinary(decimal)
print(binary)
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)

numA = 1000
numB = 1
# Repeat the process, this time creating a procedure called findMin, which will print the parameter with a smaller value.
def findMin(numA, numB):
    if numA > numB:
        return(numB)
    else:
        return(numA)

# Within the procedure, write the code to determine which of the two parameters, numberA or numberB, is the larger value. Print that value.
def findMax(numA, numB):
    if numA < numB:
        return(numB)
    else:
        return(numA)

findMin(1000, 1) # drivers for min and max
findMax(1000, 1)
# Call both functions so that the parameters numberA and numberB are given a value.

resultMin = findMin(numA, numB)
resultMax = findMax(numA, numB)

print("Between", (numA), "and ", (numB),",",(resultMin), "is the smaller number.")
print("Between", (numA), "and ", (numB),",",(resultMax), "is the bigger number.")

# Optional bonus- create a procedure that can determine the minimum or maximum value out of more than two parameters.
# haha... no .
Between 1000 and  1 , 1 is the smaller number.
Between 1000 and  1 , 1000 is the bigger number.
// Start by creating a procedure called findMax and set the parameters to numberA and numberB.
// Failed javascript attempt ignore this  .
// Within the procedure, write the code to determine which of the two parameters, numberA or numberB, is the larger value. Print that value.

// Repeat the process, this time creating a procedure called findMin, which will print the parameter with a smaller value.

// 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.

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.

x = 'APCSP'

def charToBinary(x):
    byteString = bytearray(x,'utf-8') #
    result = []
    for byteValue in byteString:
        result.append(format( byteValue, 'b'))
    print((x), 'in binary is:', (result))
charToBinary(x)

# 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']