Coding with Conditions
Grade 4 math worksheet · mathbonk.com/learn
Name: ______________________ Date: ____________
Look
- Start with 12. What is the final number?
- Start with 7. What is the final number?
- Start with 20. What is the final number?
Practice
- Program: repeat for n = 1 to 6. If n is even, clap; otherwise, stomp. What is the 5th action?
- In the same program, how many claps are there altogether?
- If the temperature is less than 10, wear a coat, otherwise wear a T-shirt. What do you wear at exactly 10 degrees?
- Start with x = 8. If x is greater than 5, add 2; otherwise subtract 2. What is x now?
- Start with 10. Repeat 3 times: if the number is even, halve it; otherwise add 1. What is the final number?
- A program repeats 3 times: jump once, then repeat 4 times: clap. How many claps are there altogether?
- Is the condition "n is greater than 5" true when n = 5?
- Find the bug: "If the light is green, stop. Else, go."
- A program repeats 5 times: if the player scored, add 10 points, otherwise add 0. The player scored on 3 of the 5 tries. What is the final score?
- Start with 3. Repeat 3 times: if the number is odd, add 4; otherwise halve it. What is the final number?
- In a program, a condition is always one of two things. What are they?
Think it through
- Draw a flowchart: if it is raining, take an umbrella; otherwise wear sunglasses.
- Explain what "otherwise" does in a program.
Challenge
- Start with 15. Repeat 2 times: if even, halve; otherwise subtract 5. What is the final number?
- Start with 24. Repeat 3 times: if the number is even, halve it; otherwise add 1. What is the final number?