Grade Conversion

From CompSciWiki
Revision as of 22:49, 3 April 2012 by MaryAnnN (Talk | contribs)

Jump to: navigation, search

COMP 1010 Home > Back to Extra Labs

Introduction

Create a program that converts a numerical grade to its corresponding letter grade. The letter grades that need assigning are (Please note that the following ranges are inclusive):
A : 80-100 (Excellent work)
B: 70-79 (Very Good)
C: 60-69 (Average)
D: 50-59 (Below Average)
F: 0-49 (Below Average)
Prompt the user to input a letter grade (between 0 and 100). Output the letter grade and a brief grade description (such as "Excellent work"). Use raw_input and print for output. Ensure that necessary validity checks are done in the program to prevent invalid (numerical) input. Use constants for the letter grade ranges. .

Step 1: Get inputs/outputs needed to solve the problem

  • input - Used to prompt the user for input
  • mark - The mark that is to be used for the computation

    Step 2: Write the program

     ####################################
    ####################################
    # This program is used to convert
    # a mark into its approparite 
    # letter grade
    
    ## Get mark from the user
    mark = input("Please enter your marks:")
    
    if (mark >= 75):
        print "Your grade is above average"
    elif (mark >= 70):
        print "Your grade is average"
    elif (mark <= 65):
        print "Your grade is below average"
    else:
        print "This is not a valid mark. Please input another mark." 

    Step 3: Contrast with Letter Grade Conversion program in Program-A-Day example

    This Python program produces exactly the same result as the Java Letter Grade Conversion program in Program-A-Day.