Note Template
What are procedures?
Fill in the blanks please:
Procedure: a named group of programming instructions that may have parameters and return values.
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 pieces or blocks
Procedural Abstraction: provides a name for a process that allows a procedure to be used only knowing WHAT it does, not HOW it does it
What are some other names for procedures?: Functions and methods
Why are procedures effective?: Convenient to change errors, ability to alter the result without actually changing the calls to the program
num = 7
def convert(num):
if num >= 1:
convert(num // 2) # double slash : divide the first number by the second, rounds to the nearest integer
print(num % 2, end = '') # end = '' signifies what will come between each printed num
# Driver Code
convert(num)
findMax = function(numberA, numberB){
if (numberA>numberB) {
max = numberA;
} else {
max = numberB;
}
console.log("The max is " + max);
};
findMin = function(numberA, numberB){
if (numberA<numberB) {
min = numberA;
} else {
min = numberB;
}
console.log("The min is " + min);
};
findMax(2,3)
findMin(6,10)
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 convert(num):
if num >= 1:
convert(num // 2) # double slash : divide the first number by the second, rounds to the nearest integer
print(num % 2, end = '') # end = '' signifies what will come between each printed num
def wordtobin(word):
word = str(word)
list = []
for letter in word:
list.append(letter)
for item in list:
index = list.index(item)
new = ord(item)
list[index] = new
for i in list:
z = list.index(i)
new = convert(i)
list[int(z)] = new
word = input("What word would you like to convert to binary?")
print(word, " to binary is:")
wordtobin(word)
word = "APCSP"
conversion = '-'.join(format(ord(x), 'b') for x in word)
print(word , "to binary is:" , conversion)