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: Methods or functions

Parameters: INput values of a procedure

Arguments: Specify

Modularity:

Procedural Abstraction:

What are some other names for procedures?:

Why are procedures effective?:

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

def DecimalToBinary(num):
    strs = ""
    while num:
        # if (num & 1) = 1
        if (num & 1):
            strs += "1"
        # if (num & 1) = 0
        else:
            strs += "0"
        # right shift by 1
        num >>= 1
    return strs
 
# function to reverse the string
def reverse(strs):
    print(strs[::-1])
 
# Driver Code
num = 7
print("Binary of num 7 is:", end=" ")
reverse(DecimalToBinary(num))
Binary of num 7 is: 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 min_max(numbers):                                      #The f before the string indicates that this is an f-string,  
  return (min(numbers), max(numbers))                      #which allows you to embed expressions inside string literals.
                                                            #The {min_value} and {max_value} inside the string are placeholders for the values of the min_value and max_value
numbers = [1, 2, 3, 4, 5]
min_value, max_value = min_max(numbers)
print(f"Min: {min_value}, Max: {max_value}")
Min: 1, Max: 5

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):
    # Convert the character to its ASCII code
    ascii_code = ord(x)
    
    # Convert the ASCII code to binary
    binary = bin(ascii_code)
    
    # Return the binary representation as a string
    return binary
APSCP = "APSCP"
for char in APSCP:
    binary = charToBinary(char)
    print(binary)
binary_list = []
for char in APSCP:
    binary = charToBinary(char)
    binary_list.append(binary)

# Concatenate the binary strings into a single string
binary_string = ''.join(binary_list)
print(binary_string)
0b1000001
0b1010000
0b1010011
0b1000011
0b1010000
0b10000010b10100000b10100110b10000110b1010000