# Test Average and Grade # This function has the user enter five test scores and then displays the letter grade for each score # and the average test score # Written by Beth Mela # Last Updated April 28, 2015 # Define constants numberOfTests=5 totalOfTestScores=0 # Define the determineGrade function def determineGrade(grade): if (grade >= 90): return "A" elif (grade >= 80): return "B" elif (grade >= 70): return "C" elif (grade >= 60): return "D" else: return "F" # Define the calcAverage function def calcAverage(totalOfTestScores): myFunctionsReturnValue=(totalOfTestScores / numberOfTests) return myFunctionsReturnValue # Assign grades to the tests for test in range(1,numberOfTests+1): grade= input('Please enter the test score for test number {}.'.format(test)) totalOfTestScores = totalOfTestScores + grade print('The letter grade for a score of {} is a(n) {}.'.format(grade,determineGrade(grade))) # Determine the average grade of all tests averageGrade= calcAverage(totalOfTestScores); # Print results print('The overall average score is: {:,.1f}.'.format(averageGrade)) print('The overall average letter grade is a(n) {}.'.format(determineGrade(averageGrade)))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question