Class 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 50. What does it print?
2.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
- Toddler
- Teenager
- Child
- Adult
3.In that same program — if the number is more than 10, print "Big"; else if the number is more than 100, print "Huge"; otherwise print "Small" — is there any number at all that makes it print Huge?
- a) Yes, any number above 100
- b) No, because anything above 100 is already above 10
- c) Yes, but only the number 100 itself
- d) Yes, any number above 10
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 49. What does it print?
6.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?
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 89. What does it print?
8.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 100, and print "Huge" if it is
- test whether the number is more than 10, and print "Big" if it is
- if neither test held, print "Small"
Answer key — Class 7 Computer Science — Choosing between more than two things
- 1. Bronze
- 2. 20 → Adult; 13 → Teenager; 9 → Child; 3 → Toddler
- 3. b) No, because anything above 100 is already above 10
- 4. Gold
- 5. Try again
- 6. Silver
- 7. Silver
- 8. 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"