0% found this document useful (0 votes)
18 views

Exercise 4 - Boolean Operators.doc

Uploaded by

krishpatel200877
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Exercise 4 - Boolean Operators.doc

Uploaded by

krishpatel200877
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

ICS2O0 Selection – Combining conditions

For each problem, create a flowchart. Write the program based on the flowchart that
you have designed.

1. Using Python, create a variable called length and width. Write a program that
prompts the user for the length and width of a rectangle. If the length and width are
positive, calculate and output the area. Otherwise, output an error message.
Sample Output
Enter the length of a rectangle:
45
Enter the width of a rectangle:
-35
Error: there cannot be a negative side length for a rectangle

2. The theatre charges a discounted admission rate for seniors (65+) or children 12
years and younger. Write a program that prompts for the age of a customer and
outputs a message indicating whether a discount rate is applied or not.
Sample Output
Enter the age of the moviegoer:
66
This moviegoer qualifies for a discount rate.
a. The theatre applies a discount of $2.5 for seniors (65+) or children 12 years
and younger. Write a program that prompts for the age of a customer and the
price of the ticket and outputs the cost of the ticket.
b. The theatre applies a discount of 15% off for seniors (65+) or children 12
years and younger. Write a program that prompts for the age of a customer
and the price of the ticket and outputs the cost of the ticket.

3. Write a program that prompts for the mark of a student (out of 100). The program
outputs the appropriate letter grade of the student. For example, if the marks is
greater than 60 AND less than 69, the letter grade is a ‘C’.
Sample Output
Enter a mark out of 100:
64
The letter grade for a 60 is a C.

a. Edit the previous question so that an error message will be displayed if a


negative mark or a mark greater than 100 is entered.
Sample Output
Enter a grade out of 100:
101
Error: 101 is not between 0 and 100

4. A trivia game asks the user three true/false questions. Write a program to record the
three answers as Boolean variables. If the two of the answers are true, the player
wins, otherwise the computer wins.
a. Modify the questions above so that points are awarded in the following
manner:
i. All three are true = 10 pts
ii. First two are true = 8 pts
iii. First is true = 4 points
iv. Last two are true = 7 pts
v. Last is true points = 3 pts
vi. All other = 1 pts
Output the number of points instead.

5. At Chen’s Video game emporium, there are two ways to earn a discount. You get
20% off your entire purchase if you are a member or you have spent over $250. If
you are a member and you have spent over $250, You will receive a discount of 25%
off. Write a program that will prompt the user for the amount spent and whether
they are a member or not. This program will output the final cost.

6. The following is a list of some of the weight classes in the International Boxing
Federation.
x - Weight Limit (in kg) Class
90.72 < x < No limit Heavyweight
79.4 < x <= 90.72 Cruiserweight
76.2 < x <= 79.4 Light Heavyweight
72.6 < x <= 76.2 Super middleweight
69.9 < x <= 72.6 Middleweight
Write a program that prompts the user for the name of a boxer and their weight. If
their weight is not on the chart, classify them as ‘unknown’. This program will output
their name and the weight class by name

You might also like