Question

In: Computer Science

Write a program that translates a letter grade into a number grade. Letter grades are A,...

  1. Write a program that translates a letter grade into a number grade. Letter grades are A, B, C, D, and F, possibly followed by + or -. Their numeric values are 4, 3, 2, 1 and 0. There is no F+ or F-. A “+” increases the numeric value by 0.3, a “–“ decreases it by 0.3. However, an A+ has value 4.0.4 pts

Enter a Letter grade: B-

The numeric value is 2.7

  1. Your code with comments
  2. A screenshot of the execution

Test Cases:

            B-   (should print 2.7)

            A+ (should print 4.0)

            B+ (should print 3.3)

            C    (should print 2.0)

            F+ (should print 0.0)

            G    (should print “no such grade”)

Python, keep it simple

Solutions

Expert Solution

Hi,

Hope you are doing fine. I have coded the above question in python. Since you have mentioned to keep it simpke, I have tried to make it as easy as possible. The logic of the code is pretty straighforward and the code is explained through comments that have been highlighted in bold. Also please have a look at the code snippet and out put to get a better understanding about the indentation and execution of the program.

Program:

#taking input from user with a prompt to enter the letter grade and storing it in grade
grade=input("Enter a Letter grade: ")

#conversion is a dictionary that store all the possible coversion of the grades in the form of key value pairs. It has all the grades given in the question
#Value of each grade is a floating point number that are as per the conditions mentioned in the question

conversion={'A':4.0,'A+':4.0,'A-':3.7,
'B':3.0,'B+':3.3,'B-':2.7,
'C':2.0,'C+':2.3,'C-':1.7,
'D':1.0,'D+':1.3,'D-':0.7,
'F':0.0,'F+':0.0,'F-':0.0}

#if grade entered by the user is not present in the dictionary as a key then
if grade not in conversion.keys():
#we print that there is no such grade
print("no such grade")

#else if the grade entered is present in the dictionary then
else:
#the value at that key is printed which would be its numeric conversion.
print("The numeric value is ",conversion[grade])

Executable code snippet from jupyter notebook:

Sample outputs of given test cases:


Related Solutions

write a Java program Write a program to assign a letter grade according to the following...
write a Java program Write a program to assign a letter grade according to the following scheme: A: total score >= 90 B: 80 <= total score < 90 C: 70 <= total score < 80 D: 60 <= total score < 70 F: total score < 60 Output - the student's total score (float, 2 decimals) and letter grade Testing - test your program with the following input data: test1 = 95; test2 = 80; final = 90; assignments...
Write a program that will calculate numerical and letter grades for a student and output a...
Write a program that will calculate numerical and letter grades for a student and output a report: The information will be in the provided data file studentGrades.txt. The data file consists of several rows of data containing a student name and information for 3 types of assignments: First Name, Last Name, number of homework grades, values for homework grades, percentage of total grade, number of program grades, values for program grades, percental of total grade, number of ex-am grades, values...
Write a program that will calculate numerical and letter grades for a student and output a...
Write a program that will calculate numerical and letter grades for a student and output a report: The information will be in the provided data file studentGrades.txt. The data file consists of several rows of data containing a student name and information for 3 types of assignments: First Name, Last Name, number of homework grades, values for homework grades, percentage of total grade, number of program grades, values for program grades, percental of total grade, number of ex-am grades, values...
Write a c++ program that given a set of letter grade/credit hour combiniation, determines the grade...
Write a c++ program that given a set of letter grade/credit hour combiniation, determines the grade point average (GPA) Each A is worth 4 points. Each B is worth 3 points. Each C is worth 2 points. Each D is worth 1 point, and Each F is worth 0 points. The total quality points earned is the sum of the product of letter grade points and associated course credit hours. The GPA is the quotient of the quality points divided...
Create a program that translates English into Pig Latin. The function will take the first letter...
Create a program that translates English into Pig Latin. The function will take the first letter of each word in the sentence only if it’s a not a vowel, and place it at the end of the word followed by “ay”. Your program must be case ​ins​ ensitive. You must write the functiontranslate() ​that takes in a single English word and ​returns​ its Pig Latin translation. Remembertranslatemusttake​onlyonewordasinput.​ ############################################################# # translate() takes a single english word translates it to #pig latin...
Create an Java application that uses a class to convert number grades to letter grades and...
Create an Java application that uses a class to convert number grades to letter grades and another class for data validation. Specifications The Grade class should have only one Instance Variable of type int. Use a class named Grade to store the data for each grade. This class should include these three methods:   public void setNumber(int number)   public int getNumber()   public String getLetter() The Grade class should have two constructors. The first one should accept no parameters and set the...
Write a program and test a program that translates the following Bubble Sort algorithm to a...
Write a program and test a program that translates the following Bubble Sort algorithm to a bubblesort function. The function's prototype is, void bubblesort(int a[], int size); Bubble Sort The inner loop moves the largest element in the unsorted part of the array to the last position of the unsorted part of the array; the outer loop moves the last position of the unsorted part of the array. The Bubble sort exchanges elements with adjacent elements as it moves the...
Write pseudocode for a function that translates a telephone number with letters in it (such as...
Write pseudocode for a function that translates a telephone number with letters in it (such as 1-800-FLOWERS) into the actual phone number. Use the standard letters on a phone pad
write a program that: 1) asks the user to enter grades, a negative number is the...
write a program that: 1) asks the user to enter grades, a negative number is the signal to stop entering. (while loop) - add each grade to a list (do not add the negative number to the list) after the while loop to enter grades is finished: 2) use a for loop on the list to calculate the average of all numbers in the list 3) use a for loop on the list to find the largest number in the...
1. ​ a)​Write a Matlab program to define student grade program and student number with if-else...
1. ​ a)​Write a Matlab program to define student grade program and student number with if-else statement logic​​​​​​​​​ b)​Write a Matlab program for sensor selection of temperature, pressure, flow sensor with if-else statement logic​​​​​​​​​ ​ 2.​Assume there are four letters from an information source with probabilities as A1 0.5 A2 0.3 A3 0.1 A4 0.1 Generate the tag and find the corresponding gaps and binary values for each stage and the sequence of the symbols which are coded are a1a3a2a4a1.​​​...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT