Last active
October 11, 2017 19:31
-
-
Save bmontana/ff3a8658ff3102fd5d7c40145ac65cc8 to your computer and use it in GitHub Desktop.
Accepts an exam score as input and prints the corresponding letter grade
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# U05_Ex03_GradingScale.py | |
# | |
# Author: Bill Montana | |
# Course: Coding for OOP | |
# Section: A3 | |
# Date: 30 Oct 2017 | |
# IDE: Pythonista for iOS | |
# | |
# Assignment Info | |
# Exercise: 3 | |
# Source: Python Programming | |
# Chapter: 5 | |
# | |
# Program Description | |
# Accepts an exam score as input and prints the corresponding letter grade | |
# | |
# Algorithm (pseudocode) | |
# Print intro | |
# Get exam score from user | |
# Get index by integer dividing by 10 | |
# Print letter grade using index | |
def main(): | |
# Print intro | |
print('This program converts a numeric grade (0-100) to a letter grade (A,B,C,D,F)\n') | |
# Get exam score from user | |
examGrade = int(input('Please enter the exam grade: ')) | |
# Get index by integer dividing by 10 | |
idx = examGrade // 10 | |
# letters = ['F'*6, 'D', 'C', 'B', 'A'] | |
letters = 'F'*6 + 'DCBAA' | |
# Print letter grade using index | |
print('An exam grade of {0} corresponds to a letter grade of {1}.'.format(examGrade, letters[idx])) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I try to use concepts from the chapter in my solutions. To that end, I select the letter grade from a string based on an index determined from the number grade. Note that my first attempt, in which I used a list for
letters
, did not work.