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
Computer Science
ScanSolve AI Answer
Question 1: Write a program that accepts marks in 4 subjects, computes total, average, and grade using if-else.
# Program using if-else
def calculate_grade(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
marks = [float(input("Enter marks for subject {}: ".format(i+1))) for i in range(4)]
total, average, grade, remark = calculate_grade(marks)
print(f"Total: {total}, Average: {average}, Grade: {grade}, Remark: {remark}")
Question 2: Write a program that accepts marks in 4 subjects, computes total, average, and grade using switch-case.
# Program using switch-case (simulated with dictionary)
def calculate_grade(marks):
total = sum(marks)
average = total / len(marks)
def get_grade_remark(avg):
switcher = {
(70, 100): ('A', 'Excellent'),
(60, 69): ('B', 'Good'),
(50, 59): ('C', 'Satisfactory'),
(40, 49): ('D', 'Pass'),
(0, 39): ('F', 'Fail'),
}
for key in switcher:
if key[0] <= avg <= key[1]:
return switcher[key]
grade, remark = get_grade_remark(average)
return total, average, grade, remark
marks = [float(input("Enter marks for subject {}: ".format(i+1))) for i in range(4)]
total, average, grade, remark = calculate_grade(marks)
print(f"Total: {total}, Average: {average}, Grade: {grade}, Remark: {remark}")
Was this helpful?
Still stuck on this one?
Ask a follow-up, and the answer starts from this question.
Got a different question?Ask your own question
More Computer Science Questions
QHow to write a C program to evaluate student grades using a switch statement and how to compile and…Q2) i) Define the term Operating System and state any two (02) of its functions. (4 Marks) ii)…QConsider the following set of marks for a class test (out of 10) for grade 8 A. Rearrange these…QThe following is record of scores obtained 30 J.H.S. 2 pupils in a test marked out of 5: 5, 4, 3, 1…QCalculate the average score for each student and the overall lowest score across all subjects…
Browse by topic:Programming