1. write-a
progsam to inpent the marks obtained
by a Student - in 3 subjects. Calculate
and print the total Average ,Highest
Marks scored, lowest marke scored, Name
The subject in which the child failed
(if any) and Grade as per the following
Table
Average Marks Grade
80 - 100 - A
60 - 79 - B
40 - 59 - C
Below 40 - Fail
Answers
Answer:
#check grade and for fail
def grade(subj):
if subj > 79:
return "A"
elif subj > 59:
return "B"
elif subj > 39:
return "C"
else:
return "fail"
#check highest and lowest marks
def check_high_low_marks(sub,marks):
global h_temp_marks
global l_temp_marks
if marks > h_temp_marks:
h_temp_marks = marks
global h_sub
h_sub = sub
if marks < l_temp_marks:
l_temp_marks = marks
global l_sub
l_sub = sub
#main
h_temp_marks = 0
l_temp_marks = 100
total_marks = 0
sub_name_marks = {}#store subject and marks in dictionary
for i in range(3):
sub = input("Enter Subject Name: ")
marks = int(input("Enter Subject Marks: "))
sub_name_marks[sub] = marks#adding it to dictionary
total_marks += marks#for calculating total marks
check_high_low_marks(sub,marks)
#print total and average marks
print("Total marks =", total_marks)
print("Average marks =", total_marks/3)
print("Highest marks in", h_sub)
print("Lowest marks in", l_sub)
#checking grade and for fail
for key in sub_name_marks:
print(key, grade(sub_name_marks.get(key)))
Explanation:k;lasd