#Intro Message print('This program finds the average score from your last 5 tests.') print #Gather Variables valOne = input('Please enter the first test score: ') print valTwo = input('Please enter the second test score: ') print valThree = input('Please enter the third test score: ') print valFour = input('Please enter the fourth test score: ') print valFive = input('Please enter the fifth test score: ') print #Decision Tree for Letter Grade def determineGrade(score): if score >= 90: return 'A' elif score >= 80: return 'B' elif score >= 70: return 'C' elif score >= 60: return 'D' else: return 'F' #Sum and Divide Function def calcAverage(one,two,three,four,five): return (one+two+three+four+five)/5 #Main Instructions def main(): print('Here are the letter grades for each of your individual tests: {}, {}, {}, {}, {}.').format(determineGrade(valOne),determineGrade(valTwo),determineGrade(valThree),determineGrade(valFour),determineGrade(valFive)) print print('Your overall letter grade for your average test score of {} is {}.').format(calcAverage(valOne,valTwo,valThree,valFour,valFive),determineGrade(calcAverage(valOne,valTwo,valThree,valFour,valFive))) main()
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