Answer to Question #338922 in Python for RENA

Question #338922

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


1
Expert's answer
2022-05-09T14:55:00-0400
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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS