Note Template
ADDITIONAL NOTES:
- New parameters and arguments give a different output
- You call a function, define it then call it then put in your parameters
- Insert values into a function for a certain output
- Splice function splits up different parts of a string
- Its a pain to rewrite code multiple times rather than defining it as a function
- Modularity is needed for large coding projects
What are procedures?
Fill in the blanks please:
Procedure: Methods or functions
Parameters: Input values of a procedure
Arguments: Specify value of values when procedure is called
Modularity: Executing the code multiple times
Procedural Abstraction: Provides a name for a process
What are some other names for procedures?: Function
Why are procedures effective?: They can repeat a code multiple times without rewriting the entire code again You can also alter the result without channging the code
decimal = 8
binary = 0
ctr = 0
new = decimal
while(new > 0):
binary = ((new%2)*(10**ctr)) + binary
new = int(new/2)
ctr += 1
#output the result
print("Binary of", decimal, " is:", binary)
const a = 30
const b = 10
if (a > b) {
console.log("Higher")
} else {
console.log("Lower")
}
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.
import math
def charToBinary(x):
l,m = [],[]
for i in x:
l.append(ord(i))
for i in l:
m.append(int(bin(i[2:])))
return m
print(charToBinary("APCSP"))
# The output shown below is the output you are supposed to get
#import math