1. write a program that accept marks in 4 subjects, the program then compute and output total, average, and grade and remark based on the following grading system. a) Use if else b) Use switch case Marks Grade Remark 70-100 A Excellent 60-69 B Good 50-59 C Satisfactory 40-49 D Pass 0-39 F Fail
This computer science problem involves algorithmic thinking and programming concepts. The solution below explains the approach, logic, and implementation step by step.
ScanSolve AI Answer
Here are two versions of a program that accepts marks in 4 subjects, computes total, average, and assigns grades and remarks based on the specified grading system.
a) Using If-Else
`python
Function to calculate total, average, grade, and remark using if-else
def calculate_grade_if_else(marks):
total = sum(marks)
average = total / len(marks)
if average >= 70:
grade = 'A'
remark = 'Excellent'
elif average >= 60:
grade = 'B'
remark = 'Good'
elif average >= 50:
grade = 'C'
remark = 'Satisfactory'
elif average >= 40:
grade = 'D'
remark = 'Pass'
else:
grade = 'F'
remark = 'Fail'
return total, average, grade, remark
Input marks
marks = [float(input(f"Enter marks for subject {i+1}: ")) for i in range(4)]
total, average, grade, remark = calculate_grade_if_else(marks)
Output results
print(f"Total: {total}, Average: {average}, Grade: {grade}, Remark: {remark}")
`
b) Using Switch Case (Python does not have a built-in switch case, but we can simulate it using a dictionary)
`python
Function to calculate total, average, grade, and remark using a simulated switch case
def calculate_grade_switch_case(marks):
total = sum(marks)
average = total / len(marks)
Simulating switch case using a dictionary
switch = {
(average >= 70): ('A', 'Excellent'),
(average >= 60): ('B', 'Good'),
(average >= 50): ('C', 'Satisfactory'),
(average >= 40): ('D', 'Pass'),
}
grade, remark = next((value for key, value in switch.items() if key), ('F', 'Fail'))
return total, average, grade, remark
Input marks
marks = [float(input(f"Enter marks for subject {i+1}: ")) for i in range(4)]
total, average, grade, remark = calculate_grade_switch_case(marks)
Output results
print(f"Total: {total}, Average: {average}, Grade: {grade}, Remark: {remark}")
`
Summary
Both programs calculate the total and average of marks entered for four subjects and determine the grade and remark based on the specified grading system using different control structures.