ICS3C Unit 2 - Programming (Module VII)
ICS3C Unit 2 - Programming (Module VII)
MODULE VII
SELECTION
ICS3C Programming
Learning Goals –
Module VII to be able to write computer
programs that include a
Selection decision structure for two
choices
Part A If-Then-Else
1. Open template, then enter the following program and save as pr7_1:
cls()
print()
print("Thank you for using my program.")
This program uses a simple if... else... structure to print one of two possible
messages depending on whether the variable age is at least 18 or not. If the condition
age >= 18 is true then the first message is printed. If it is false then the second
message is printed.
_____________________________________________________________________________________
Page 7-2
ICS3C Programming
2. Markham Parks and Rec is planning a ski day for young children. Town employees must
pay $42 per child. Other Markham residents must pay $50 per child. Write a program
that asks the user if he/she is a town employee and then asks the user how many
children he/she wishes to sign up for the ski day. Your program should then tell the user
the cost per child and the total cost. Save as pr7_2. Use only one if statement.
The command number = randint(0, 3) will assign a random number from 0 to 3 to number
You can use this function to come up with many different random numbers, e.g.:
cls()
number1 = randint(0, 9)
number2 = randint(0, 9)
Add statements that will tell the user if their answer is correct or not. If the answer is not
correct, tell the user the correct answer. Use only one if.
2. Create a program for primary students to practice subtraction. (Remember that they do
not know about negative numbers.) Your program will generate 2 integers from 1 to 10
and then give the user a subtraction question with these numbers. Tell the user if their
answer is correct or incorrect. If the answer is correct, draw a happy face on the screen.
If the answer is not correct, tell the user the correct answer. Save as pr7_4.
_____________________________________________________________________________________
Page 7-3
ICS3C Programming
Part C Efficiency
Suppose you were asked to write a program asking a person if they had a two-door car or a
four-door car. Then you were to draw a picture of a car with the appropriate number of doors,
depending on what they entered. If they entered a two-door car then the picture would be of a
car with one door. If they entered a four-door car, the picture would be of a car with two doors.
To draw a picture of a car, you would need to write the code for the wheels, the body, the roof
and windshields, and the lights. You may even need to code a road for the car to sit on. Why
would you put all this code twice?
1. Write a program that asks a user how many windows there are on the second floor of
their house. Give them a choice of two or three windows. After they have entered their
response, have a picture drawn that has the appropriate number of windows appear on
the second floor. Be efficient with your code!! Save as pr7_5.
_____________________________________________________________________________________
Page 7-4