Click here to Skip to main content
15,880,972 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Write a program that will repeatedly take (for a student) input of this type: course_no, number_of_credits, and grade_received (eg. CSE101 4 A). These inputs are for the courses the student has done in the semester. If no input is given (i.e. just a return), that means no courses are left. From this data, print the transcript for the semester for the student as:

Course_no: grade
Course_no: grade
….

SGPA: n.nn (two decimal places)

In the transcript, the records should be printed such that they are sorted by the course_no (hint: when sorting a list of tuples/lists, the default sorting is with the first element of the tuple/list).

The course numbers are an alphanumeric string with capital letters in the start and digits at the end (e.g. CSE101, CSSS21), credits can be 1, 2 or 4, and grade can be A+ (10), A(10), A-(9), B(8), B-(7), C(6), C-(5), D(4), F(2) (the number in () is their numeric equivalent for SGPA calculation.) The SGPA is computed as (sum of: credits*grade/ total_credits). If any input is not valid, print a suitable message ("improper course no", "incorrect credit", or "incorrect grade") and ignore that input.

What I have tried:

Python
while True:

    course_no=int(input("enter course number: "))
    number_of_credits=int(input("enter number of credits: "))
    grade_received=int(input("enter grade received: "))
    l1=[]
    l1.append(course_no)
    l1.append(number_of_credits)
    l1.append(grade_received)
Posted
Updated 7-Jan-23 23:40pm
v2

The course number and grade, as shown in the question, are strings, not integers. So your code should be:
Python
course_no = input("enter course number: ")
number_of_credits = int(input("enter number of credits: "))
grade_received = input("enter grade received: ")

You then need to record the details in a suitable container, such as a set or map, in order to produce the correct output. See 5. Data Structures — Python 3.11.1 documentation[^].

[edit]
Corrected the grade_received item as noted by CPallini (aka Hawkeye) in Solution 2.
[/edit]
 
Share this answer
 
v2
Comments
CPallini 8-Jan-23 4:59am    
5.
Note, grade is a string as well.
Richard MacCutchan 8-Jan-23 7:05am    
Thanks, I missed that.
The input data types are:
course - string
credits - integer
grade_- string

You are required to validate inputs:
  • course must be a string starting with capital letters and ending with digits. You may either check it iterating over its character or using Python pattern matching facilities.
  • Checking for credits validity is very simple, since it must be either 1, 2 or 4.
  • For grade you need both to validate the input and to translate it to a numeric value (in order to compute the SGPA), a simple function can fullfill both the task at the same time, e.g:
    Python
    def grade_val(grade):
      d = { "A":10, "A+":10, "A-":9, "B":8, "B-":7, "C":6, "C-":5, "D":4, "F":2 }
      if grade in d:
        return d[grade]
      else:
        return -1 # this signals an invalid input


Once you've correctly handled the input values then you have to sort the data and produce the outputs. Try to proceed this way and post specific questions here if you are stuck.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900