Lesson 3.12 3.13 blog
- Notes
- Quiz
- Determining the Result of a Procedure
- Keyword
- Parameter
- Modularity
- Shared Features
- Vocabulary:
- Javascript vs. Python
- Parameters
- Hacks
questionNum = 3
correct = 0
questions = [
"What is are correct names for a procedure? \n A) Method \n B) Function \n C) Both",
"What is a procedure? \n A) Sequencing \n B) Selection \n C) Iteration \n D) All",
"Use this for following question: \n def inchesToFeet(lengthInches): \n\t lengthFeet = lengthInches / 12 \n\t return lengthFeet \n\n What is the procedure name, the parameter, and what the procedure returns? \n A) feetToInches, lengthInches, lengthMeters \n B) inchesToFeet, lengthInches, lengthFeet \n C) inchesToFeet, lengthFeet, lengthInches \n D) lengthInches, inchesToFeet, lengthFeet"]
answers = ["c", "d", "b"]
def qna(question, answer):
print("Question:", question)
response = input()
print("Answer:", response)
if response.lower() == answer:
print("Correct :) \n")
global correct
correct += 1
else:
print("Incorrect :( \n")
for x in range(questionNum):
qna(questions[x], answers[x])
print("Score:", correct, "/ 3")
Determining the Result of a Procedure
- You can determine function parameters and value and statements with syntax.
- A return statement will exit the function and allow python to execute the program.
Example:
def divide(num1,num2): x = num1/num2 return x
- Function parameter are used when calling function for a result.
Keyword
- Modularity - breaking a complex program into smaller, independent parts, modules.
- Abstraction - hiding the details of how a system works and exposing only the essential features.
- Duplication - having multiple duplicate codes, decreasing efficiency.
- Logic - the sequence of steps a computer follows to execute a program.
Collegeboard
Above, the function is defined as PROCEDURE. The function is then named with procName, the name of function as display. parameter1, parameter2,... are variables that can be predefined elsewhere and repeatedly used in the same function. Block of statements are just things that you would place inside a function to complete a certain task, such as print().
Topic 3.13 (3.B):
- Explain, in your own words, why abstracting away your program logic into separate, modular functions is effective
- Create a procedure that uses other sub-procedures (other functions) within it and explain why the abstraction was needed (conciseness, shared behavior, etc.)
- Add another layer of abstraction to the word counter program (HINT: create a function that can count the number of words starting with ANY character in a given string -- how can we leverage parameters for this?)
Topic 3.13 (3.C):
- Define procedure names and arguments in your own words.
- Code some procedures that use arguments and parameters with Javascript and HTML (make sure they are interactive on your hacks page, allowing the user to input numbers and click a button to produce an output)
- Add two numbers
- Subtract two numbers
- Multiply two numbers
- Divide two numbers