Grade 7 Computer Science — Choosing between more than two things
Follow a chain of tests in which the first one that comes out true wins, and say which branch a program takes.
Name: ________________________
1.A program says: if the score is at least 90, print "Gold"; else if the score is at least 70, print "Silver"; else if the score is at least 50, print "Bronze"; otherwise print "Try again". The score is 89. What does it print?
2.Put these three lines into the order that makes the chain work as it is meant to: numbers above 100 should give Huge, and other numbers above 10 should give Big.
- test whether the number is more than 10, and print "Big" if it is
- test whether the number is more than 100, and print "Huge" if it is
- if neither test held, print "Small"
3.A program says: if the number is more than 10, print "Big"; else if the number is more than 100, print "Huge"; otherwise print "Small". The number is 500. What does it print?
- a) Big
- b) Both Big and Huge
- c) Small
- d) Huge
4.A program says: if the score is at least 90, print "Gold"; else if the score is at least 70, print "Silver"; else if the score is at least 50, print "Bronze"; otherwise print "Try again". The score is 95. What does it print?
5.A program says: if the score is at least 90, print "Gold"; else if the score is at least 70, print "Silver"; else if the score is at least 50, print "Bronze"; otherwise print "Try again". The score is 70. What does it print?
6.A program says: if the number is less than 0, print "Negative"; else if the number is 0, print "Zero"; otherwise print "Positive". The number is 7. What does it print?
7.A program says: if the score is at least 90, print "Gold"; else if the score is at least 70, print "Silver"; else if the score is at least 50, print "Bronze"; otherwise print "Try again". The score is 49. What does it print?
8.A program says: if the age is at least 18, print "Adult"; else if the age is at least 13, print "Teenager"; else if the age is at least 5, print "Child"; otherwise print "Toddler". Match each age to what the program prints.
- 20
- 13
- 9
- 3
- Child
- Teenager
- Toddler
- Adult
Answer key — Grade 7 Computer Science — Choosing between more than two things
- 1. Silver
- 2. 1. test whether the number is more than 100, and print "Huge" if it is 2. test whether the number is more than 10, and print "Big" if it is 3. if neither test held, print "Small"
- 3. a) Big
- 4. Gold
- 5. Silver
- 6. Positive
- 7. Try again
- 8. 20 → Adult; 13 → Teenager; 9 → Child; 3 → Toddler