0

So Below is my code, and what I am trying to do is keep the marks entered between 0 and 100 If they aren't to then give them an error or something. Thank you.

    print("please enter your 5 marks below")

    #read 5 inputs
    mark1 = int(input("enter mark 1: "))
    mark2 = int(input("enter mark 2: "))
    mark3 = int(input("enter mark 3: "))
    mark4 = int(input("enter mark 4: "))
    mark5 = int(input("enter mark 5: "))

    #create array/list with five marks
    marksList = [mark1, mark2, mark3, mark4, mark5]

    #print the array/list
    print(marksList)

    #calculate the sum and average
    sumOfMarks = sum(MarksList)
    averageOfMarks = sum(marksList)/5

    #display results
    print("The sum of your marks is: "+str(sumOfMarks))
    print("The average of your marks is: "+str(averageOfMarks))
Bidja001
  • 1
  • 1
  • Check out this [answer](https://stackoverflow.com/a/52696312/15202496). This should help you. – Marcel Sep 15 '22 at 06:21

1 Answers1

0

Use this way(while):

i=0
marksList = []
print("please enter your 5 marks below")

while i < 5:
    mark = int(input(f"enter mark{i+1}: "))
    
    if mark<=100 and mark>=0:
        marksList.append(mark)
        i+=1
    else:
        print("Please enter between 0 and 100")
   
  

#print the array/list
print(marksList)

#calculate the sum and average
sumOfMarks = sum(marksList)
averageOfMarks = sum(marksList)/5

#display results
print("The sum of your marks is: "+str(sumOfMarks))
print("The average of your marks is: "+str(averageOfMarks))
Shahab Rahnama
  • 982
  • 1
  • 7
  • 14