Difference between revisions of "Grade Conversion"

From CompSciWiki
Jump to: navigation, search
m
Line 10: Line 10:
 
|Body=
 
|Body=
  
===[[Step 1: Get inputs/outputs needed to solve the problem ]]===
+
===Step 1: Get inputs/outputs needed to solve the problem===
  
 
<li>input - Used to prompt the user for input
 
<li>input - Used to prompt the user for input
 
<li>mark - The mark that is to be used for the computation
 
<li>mark - The mark that is to be used for the computation
  
===[[Step 2: Write the program]]===
+
===Step 2: Write the program===
  
 
{{CodeBlock
 
{{CodeBlock
Line 37: Line 37:
 
}}
 
}}
  
===[[Step 3: Contrast with Letter Grade Conversion program in Program-A-Day example]]===
+
===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.
 
This Python program produces  exactly the same result as the Java Letter Grade Conversion program in Program-A-Day.
 
}}
 
}}

Revision as of 07:01, 4 April 2012

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 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.