Write a program that lets user enter in a potentially unlimited series of subject marks from 0 to 100. Ensure that the numbers entered are greater than 0 and less than 100. You cannot assume that the user will enter an integer or a float. User can enter both float and integer values. If they input a negative number or a number more than hundred you should continually prompt them to enter a valid number until they do so. When the user enters a the line ”end” you should stop collecting marks.
Then use their input to generate a summary report that includes Total marks, Average mark, Highest mark and the lowest mark. Sample output is given below.
Enter a mark, 0 to 100: apple
That's not a valid mark!
Enter a price, 0 to end: -5
Marks must be positive!
Enter a mark, 0 to 100: 10
Enter a mark, 0 to 100: 20
Enter a mark, 0 to 100: 30
Enter a mark, 0 to 100: 40
Enter a mark, 0 to 100: 50
Enter a mark, 0 to 100: end
Total marks: 150.0
Average marks: 30.0
Highest mark: 50.0
Lowest mark: 10.0
lowest_mark = 100
highest_mark = 0
total_marks = 0
count = 0
mark = 0
while mark != 'end':
mark = input("Enter a mark, 0 to 100: ")
if mark == 'end':
continue
if mark.isdigit():
mark = int(mark)
if mark > 100:
print("Marks must between 0 to 100")
else:
count += 1
total_marks += mark
if mark < lowest_mark:
lowest_mark = mark
if mark > highest_mark:
highest_mark = mark
elif mark.isalpha():
print("That's not a valid mark!")
else:
if int(mark) < 0:
print("Marks must be positive!")
print("Total marks: ", total_marks)
print("Average marks: ", total_marks / count)
print("Highest mark: ", highest_mark)
print("Lowest mark: ", lowest_mark)
Comments
Leave a comment