Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Having trouble with some Python homework

Question: Write a python program using a "While" loop that will ask for the user to input exam scores. You should start by asking the user how many scores they would like to enter. Then use a loop to request each score and add it to a total. Finally, calculate and display the average for entered scores.
The current code I have got is listed below though whenever I try to run it to see if it works, is comes up with Syntax Error: Invalid Syntax on the else.
I tried without else inside and outside the while loop and it came up with SyntaxErorr: Invalid Syntax. Perhaps you forgot a comma?

examNum = examCount
examCount = int(input("How many scores would you like to enter?"))

totalExam = (examCount + 1)
totalScore = sum(examScore)

while examNum  < examCount:
    examScore = int(input("Input your exam score."))
    else:
        print("Your average score is" totalScore)

Note: This is my first time doing Python in 5 – 10 years so I am back to square one with figuring everything else. I’m sure there is a obvious and easy work around but I’d appreciate any help.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try this one:

examCount = int(input("How many scores would you like to enter?"))

exams = examCount
totalScore = 0

while examCount > 0:
    examScore = int(input("Input your exam score."))
    examCount -= 1
    totalScore += examScore

print(totalScore/exams)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading