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

Python Homework 5

Homework 5 focuses on using while loops in Python to calculate the maximum, minimum, and average of exam marks input by the user, with incomplete code sections to be filled in. Additionally, it includes a challenge to simulate rolling a die 6000 times to count the occurrences of sixes, along with a request for testing methods. The document is structured to guide students in completing programming tasks and understanding while loops.

Uploaded by

louis.mutzig
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Python Homework 5

Homework 5 focuses on using while loops in Python to calculate the maximum, minimum, and average of exam marks input by the user, with incomplete code sections to be filled in. Additionally, it includes a challenge to simulate rolling a die 6000 times to count the occurrences of sixes, along with a request for testing methods. The document is structured to guide students in completing programming tasks and understanding while loops.

Uploaded by

louis.mutzig
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Homework 5 While loops

Introduction to Python

Homework 5: While loops


1. Here is the code for a program to find and print the maximum, minimum and average of
several exam marks (all integers) entered by the user, to the nearest whole number.
The end of input is signalled by an entry of -1.
Some lines of code are missing or incomplete. The lines are marked with *****.
Fill in the missing code.
#Program name: L5 HW5 exam marks.py
#Program find maximum, minimum and average exam mark

total = number of marks x average marks


mark = int(input("Enter first exam mark: "))
maxMark = mark+average

minMark = maxMark-average

numberOfMarks = all of the marks added together

while mark < min mark___*****


total = total + mark
if mark < minMark:
minMark = mark

if *****
maxMark = mark
mark = int(input("Enter next exam mark, -1 to end: "))

averageMark = mark *****

print ("Maximum mark =",maxMark)


print ("Minimum mark =",minMark)
print("Average mark =",averageMark)
input("Press Enter to exit ")
[7]

1
Homework 5 While loops
Introduction to Python

Challenge

2. (a) Write a program to count the number of sixes thrown in a simulation of a die being
thrown 6000 times.
Remember to import the Python module random at the start of the program.
To generate a random number between 1 and 6, use the statement
throw = random.randint(1,6) [7]

(b) Describe how you could test whether your program is working correctly. [4]

2
Homework 5 While loops
Introduction to Python
[Total 18 marks]

You might also like