Skip to content

Instantly share code, notes, and snippets.

@bmontana
Last active October 11, 2017 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmontana/ff3a8658ff3102fd5d7c40145ac65cc8 to your computer and use it in GitHub Desktop.
Save bmontana/ff3a8658ff3102fd5d7c40145ac65cc8 to your computer and use it in GitHub Desktop.
Accepts an exam score as input and prints the corresponding letter grade
# 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()
@bmontana
Copy link
Author

bmontana commented Oct 11, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment