# PSU 161 # Debugging Example # Can you find the error? # Hint: Try a grade point that includes a C- grade = "" creditHours = 0 index = 0 pointValue = 0 qualityPoints = 0 accumulatedQPoints = 0 accumulatedCHours = 0 # This is the grades = ("A", "A-", "B+", "B", "B-","C+", "C", "C-","D+", "D", "D-","F") gradeValues = (4.0, 3.67, 3.33, 3.0, 2.67, 2.33, 2.0, 10.67, 1.33, 1.0, .67, 0.0) print ("Welcome to the GPA calculator.") grade = input ("Enter a grade (or STOP to stop and compute GPA) ") creditHours = int(input("How many credits was this class? ")) # What happens if I type STOP right off the bat? Is that also a semantic error? while (grade != "STOP"): index = grades.index(grade) pointValue = gradeValues[index] qualityPoints = pointValue * creditHours accumulatedQPoints = accumulatedQPoints + qualityPoints accumulatedCHours = accumulatedCHours + creditHours grade = input ("Enter a grade (or STOP to stop and compute GPA) ") if (grade == "STOP"): break credit = int(input("How many credits was this class? ")) print ("The GPA is:", round(accumulatedQPoints / accumulatedCHours, 2))
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