GOAL: Students will be able to…
- Explain the preconditions and postconditions of a function
- Create clear and readable comments in their code that help the reader understand the code
- Explain the purpose of comments
- What should be true after the function is called
DO THE FOLLOWING IN ORDER:
- Do: 1.6.2 Top Down Design and Decomposition Quiz
- Do the Planning Programs 1 activity–get it from your teacher–work with a partner
Click on example 1.7.3 Hurdle Karel. Read the code in green. What purpose do you think the code serves in the program? Does the code in green affect the program?
Display exercise 1.7.4 The Two Towers + Comments
Can you identify the direction and avenue that Karel faces in the starting world? This is known is as a precondition.
Can you identify the direction and avenue that Karel faces in the result world? Also note the amount of balls in the tower and how many were built. This is known is as a postcondition.
Complete The Two Towers + Comments exercise in pairs or individually.
Because of your hard work with defining and calling functions, you have unlocked the super powers of Karel. These super powers are the ability to turn right and turn around without having to define it as a separate function.
Examine the example in Hurdle Karel (with SuperKarel).
*Students complete The Two Towers + Super Karel using the turnRight() command.
- If time permits: Go back through previous Karel exercises and add pre and postconditions to your code
- FYI: CodeHS Online Textbook–use this as a resource
- BEFORE YOU LEAVE, WRITE ABOUT THE FOLLOWING in the Word Online file named Web Apps & Coding for this class (you will write in this file daily):
- What are the two types of comments?
- What is the benefit of using comments?
- Are there times you wouldn’t write a comment? Why?