# ------------------------------------------------------------ #Student: Austin Wells #Class: CIS122 #Date: 4/30/2015 #Program Title: Chapter 6 Programming Excercise 7.py #(Test Average and Grade) #Program Description: The program prompts the user for 5 test scores #and displays the letter grade per score and the average score and its letter grade # ------------------------------------------------------------ # Prints out the score and letter grade def printStuff(printStr1, score, printStr2, grade): print '{0}{1}, {2}{3}' .format(printStr1, score, printStr2, grade) # prompts user for input. def promptForInput(strPrompt, numRepetition): argArray = [] for i in range(0,numRepetition): argArray.append(int(raw_input(strPrompt + ": "))) print '{}' .format(argArray[i]) return argArray #calculates the average of the scores def calcAverage(argInput): scoreAverageVar = 0 for i in range(0, len(argInput)): scoreAverageVar += argInput[i] scoreAverage = scoreAverageVar / len(argInput) return scoreAverage # determine the letter grade def determineGrade(argInput): count = 0 for i in range(0, len(argInput)): if(argInput[i] <60): grade = "F" elif (argInput[i] >= 60 and argInput[i] <= 69): grade = "D" elif (argInput[i] >= 70 and argInput[i] <= 79): grade = "C" elif (argInput[i] >= 80 and argInput[i] <= 89): grade = "B" else: grade = "A" count += 1 if(count <= len(argInput)-1): printStuff("With a score of ",argInput[i], "The letter grade is a ",grade) else: printStuff("With an average score of ",argInput[i], "The letter grade is a ",grade) return grade #main driver function def main(): try: arrayArg = promptForInput("Please enter a test score between 0 and 100", 5) arrayArg.append(calcAverage(arrayArg)) determineGrade(arrayArg) except (ValueError): print '\n\nInvalid input. You have entered a non integer. Please enter an integer' except (EOFError): print '\n\nInvalid input. You have forgotten to add input. Please Reset program and Please enter an integer' 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