Created
August 24, 2015 23:29
-
-
Save bruab/87262e2eceb8f0577c15 to your computer and use it in GitHub Desktop.
CS 294 - Grade Calculator Script
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
#!/usr/bin/env python | |
import argparse | |
def get_letter_grade(points): | |
"""Return letter grade (A-F) based on 100 point scale""" | |
if points >= 90: | |
return 'A' | |
elif points >= 80: | |
return 'B' | |
elif points >= 70: | |
return 'C' | |
elif points >= 60: | |
return 'D' | |
else: | |
return 'F' | |
# Parse command line arguments | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-ap', '--assignment_points', type=int, required=True) | |
parser.add_argument('-bp', '--blog_points', type=int, required=True) | |
parser.add_argument('-pp', '--project_points', type=int, required=True) | |
args = parser.parse_args() | |
# Add up points and convert to letter grade; print result | |
total_points = args.assignment_points + args.blog_points + args.project_points | |
grade = get_letter_grade(total_points) | |
print("Your grade is: " + grade) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment