[go: up one dir, main page]

0% found this document useful (0 votes)
156 views3 pages

Python Exam Practice Questions

Uploaded by

james downing
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)
156 views3 pages

Python Exam Practice Questions

Uploaded by

james downing
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/ 3

Python Practice Questions (Based on Exam Guide)

1. Update the Output Message

Change the print statement to display a title and the mean on a new line.

Reference Guide: print(x), \n (new line)

print("Student Results Analysis\nMean percentage mark is:", arithmetic_mean)

2. Use Built-in Functions to Calculate the Mean

Replace manual sum and count with built-in functions.

Reference Guide: sum(L), len(x), /

arithmetic_mean = sum(results) / len(results)

3. Print the Grade for the Mean

Use the get_grade function to print the grade of the average mark.

Reference Guide: def function(), return, print(x)

mean_grade = get_grade(arithmetic_mean)
print("Grade awarded:", mean_grade)

4. Print Each Result with Grade

Loop through results and print each mark with its grade.

Reference Guide: for <variable> in <list>, function()

for mark in results:


print("Mark:", mark, "-> Grade:", get_grade(mark))

5. Count Each Grade

Count how many students got each grade using if/elif/else.


Python Practice Questions (Based on Exam Guide)

Reference Guide: if/elif/else, ==, +=, for <variable> in <list>

distinction_count = 0
upper_merit_count = 0
unsuccessful_count = 0

for mark in results:


grade = get_grade(mark)
if grade == "Distinction":
distinction_count += 1
elif grade == "Upper Merit":
upper_merit_count += 1
else:
unsuccessful_count += 1

print("Distinction:", distinction_count)
print("Upper Merit:", upper_merit_count)
print("Unsuccessful:", unsuccessful_count)

6. Display a Grade Bar Chart

Use asterisks to create a simple horizontal bar chart of grade counts.

Reference Guide: print(x), * for string repetition

print("Grade Distribution:")
print("Distinction:", "*" * distinction_count)
print("Upper Merit:", "*" * upper_merit_count)
print("Unsuccessful:", "*" * unsuccessful_count)

7. Display the Highest Mark and its Grade

Use max() to find and display the highest mark and its grade.

Reference Guide: max(L), print(x), function()

highest = max(results)
print("Highest mark:", highest)
print("Grade:", get_grade(highest))

8. Add 'Lower Merit' to the Grade Function

Extend the grading function to include a new category for scores 50-64.
Python Practice Questions (Based on Exam Guide)

Reference Guide: def function(), if/elif, >=, return

def get_grade(result):
grade = "Unsuccessful"
if result >= 80:
grade = "Distinction"
elif result >= 65:
grade = "Upper Merit"
elif result >= 50:
grade = "Lower Merit"
return grade

9. Print the Median Value

Sort the results and calculate the median.

Reference Guide: sorted(L), %, //, +, /

sorted_results = sorted(results)
N = len(sorted_results)
if N % 2 == 1:
median = sorted_results[N // 2]
else:
median = (sorted_results[N // 2 - 1] + sorted_results[N // 2]) / 2
print("Median is:", median)

10. Detect Invalid Marks

Check and report any values outside 0-100.

Reference Guide: for <variable> in <list>, <, >, or, print(x)

for mark in results:


if mark < 0 or mark > 100:
print("Invalid mark detected:", mark)

You might also like