FORECAST PRACTICE EXAM
This practice exam includes PLS hints shown in yellow boxes. In the REAL EXAM, you will NOT see these hints β you must find the information yourself in the Programming Language Subset (PLS) document provided. Use this practice to learn WHERE to find information in the PLS!
A program calculates the cost of hiring a bicycle. The hire cost is calculated by multiplying the number of hours by the hourly rate. A discount of 15% is applied if the customer is a member.
The program must:
Test data:
| Hours | Member | Expected Output |
|---|---|---|
| 3 | N | Β£25.50 |
| 4 | Y | Β£28.90 |
| 2 | Y | Β£14.45 |
Open file Q01.py. Amend the code to:
cost = hours Γ rateA program uses turtle graphics to draw a simple house shape. The program has errors and does not work correctly.
The house consists of:
Open file Q02.py. Amend the code to:
import turtlmyTurtle = turtle.Turtle(myTurtle.forwrd(100)setheading() doesmyTurtle.left(90)A program calculates the Body Mass Index (BMI) for a user. The BMI is used to determine if a person is underweight, normal weight, overweight, or obese.
The formula to calculate BMI is:
The BMI categories are:
| BMI Range | Category |
|---|---|
| Below 18.5 | Underweight |
| 18.5 to 24.9 | Normal |
| 25.0 to 29.9 | Overweight |
| 30.0 and above | Obese |
Test data:
| Weight | Height | BMI | Output |
|---|---|---|---|
| 70 | 1.75 | 22.86 | Normal |
| 95 | 1.80 | 29.32 | Overweight |
| 50 | 1.70 | 17.30 | Underweight |
| -5 | 1.70 | β | Invalid input |
The program must:
A program generates a password by taking a word from the user and encoding it. Each letter is replaced with the next letter in the alphabet (A becomes B, Z becomes A). The program also appends the length of the original word to the end.
The program loops continuously until the user enters an empty string to stop.
Test data:
| Input | Output |
|---|---|
| CAT | DBU3 |
| ZEBRA | AFCSB5 |
| "" (empty) | Exits program |
The lines of code in the program are mixed up.
Amend the code to make the program work and produce the correct output. You will need to rearrange the lines.
The code uses these concepts:
ord() to get the ASCII value of a characterchr() to convert an ASCII value back to a characterDo not change the indentation of any line.
A sports club stores member attendance data in a file. Each line of the file contains a member name followed by their attendance count, separated by a comma.
Example file content (Q05_DATA.txt):
A program and subprogram are required to:
Expected output for the example data:
Expected content of Q05_OUTPUT.txt:
Amend the program and subprogram to meet these requirements:
calculateAverage() that takes a list of attendance values and returns the averagesplit() function to separate the name and attendance on each linecalculateAverage() function with the attendance valuesA library system stores book information in a two-dimensional array. Each record contains: ISBN, Title, Author, Year Published, and Available (True/False).
The array is sorted alphabetically by Title.
Write a program to meet these requirements:
Inputs
Process
Outputs
Use comments, white space and layout to make the program easier to read and understand.