Sep 11: Quiz1, def Statements
Learning Objectives
After today's class, you should be able to:
- Explain the flow of execution from one function to another.
- Describe the syntax of function definitions and function calls.
- Write short functions that have parameters and return values.
Reminders¶
- Read Week 4 Reading and Activities– ideally:
- 1st half before Friday
- 2nd half before Monday
- Submit HW 4 – ideally:
- 1 and 2 before Friday
- 3 and 4 before Monday
HW3 Debrief¶
Some highlights:
Quiz 1¶
[25 min]
Instructions:
This a timed quiz. You will have 25 minutes to complete. The quiz is on paper. Please write neatly so that your answers can be accurately graded. Remember to write your name at the top of the page.
MiniLecture¶
POGIL Activity¶
- Defining Functions
- If you are absent today, complete this activity at home
- Bring your completed activity to class or office hours
- Python Tutor
- Visualize the flow of execution and memory contents
Example Code¶
Model 1
def model_one():
word = input("Enter a word: ")
L = len(word)
ans = word * L
print(ans)
def main():
print("Starting main...")
model_one()
print("All done!")
main()
Model 2
def model_two(word):
ans = word * len(word)
print(ans)
def main():
print("Starting main...")
w = input("Enter a word: ")
model_two(w)
print("All done!")
main()
Model 3
def model_three(word):
ans = word * len(word)
return ans
def main():
print("Starting main...")
w = input("Enter a word: ")
result = model_three(w)
print(result)
print("All done!")
main()