DEV Community

Ajay
Ajay

Posted on Edited on

Python learning series | list Programs solving

The given list , the scored mark in quartaly exam(q),

halfy exam(h) and annual exam

q = [90,80, 67, 58, 49]
h = [87,89, 99, 47, 36]
a = [56,78, 46, 67, 69]

Enter fullscreen mode Exit fullscreen mode
  • To find total Mark in each exam
  • To find highest mark in each exam
  • To find the highest mark position in each exam
  • To find overall highest mark in all exam
  • To find Single subject average in all exam

1) To find total Mark in each exam

q = [90,80, 67, 58, 49]
h = [87,89, 99, 47, 36]
a = [56,78, 46, 67, 69]

each_exam = [q,h,a]

total = 0
i = 0
while i < len(each_exam[0]):
    total += q[i]
    i+=1
print("Total mark in q : ",total)


total = 0
i = 0
while i < len(each_exam[1]):
    total += h[i]
    i+=1
print("Total mark in h : ",total)


total = 0
i = 0
while i < len(each_exam[2]):
    total += a[i]
    i+=1
print("Total mark in a : ",total)

Enter fullscreen mode Exit fullscreen mode

output:

Total mark in q :  344
Total mark in h :  358
Total mark in a :  316

Enter fullscreen mode Exit fullscreen mode

2) To find highest mark in each exam

highest = 0
total = 0
i = 0
while i < len(each_exam[0]):
    if q[i] > highest:
        highest = q[i]
    i+=1
print("Highest mark in q : ",highest)

highest = 0
i = 0
while i < len(each_exam[1]):
    if h[i] > highest:
        highest = h[i]
    i+=1
print("Highest mark in h : ",highest)

highest = 0
i = 0
while i < len(each_exam[2]):
    if a[i] > highest:
        highest = a[i]
    i+=1
print("Highest mark in a : ",highest)
Enter fullscreen mode Exit fullscreen mode

*Output : *

Highest mark in q :  90
Highest mark in h :  99
Highest mark in a :  78
Enter fullscreen mode Exit fullscreen mode

3) To find the highest mark position in each exam

subject_position = 0
highest = 0
total = 0
i = 0
while i < len(each_exam[0]):
    if q[i] > highest:
        highest = q[i]
        subject_position = i + 1
    i+=1
print("Highest mark in q : ",highest)
print("Highest_Mark in q subject is : " , subject_position )

subject_position = 0
highest = 0
i = 0
while i < len(each_exam[1]):
    if h[i] > highest:
        highest = h[i]
        subject_position = i + 1
    i+=1
print("Highest mark in h : ",highest)
print("Highest_Mark in q subject is : " , subject_position )

subject_position = 0
highest = 0
i = 0
while i < len(each_exam[2]):
    if a[i] > highest:
        highest = a[i]
        subject_position = i + 1
    i+=1
print("Highest mark in a : ",highest)
print("Highest_Mark in q subject is : " , subject_position )
Enter fullscreen mode Exit fullscreen mode

output :

Highest mark in q :  90
Highest_Mark in q subject is :  1
Highest mark in h :  99
Highest_Mark in q subject is :  3
Highest mark in a :  78
Highest_Mark in q subject is :  2

Enter fullscreen mode Exit fullscreen mode

4) To find overall highest mark in all exam

highest_score = 0
exam = ""
highest = 0
total = 0
i = 0
while i < len(each_exam[0]):
    if q[i] > highest:
        highest = q[i]
    i+=1
if highest > highest_score :
    highest_score = highest
    exam = "Exam q"

highest = 0
i = 0
while i < len(each_exam[1]):
    if h[i] > highest:
        highest = h[i]
    i+=1
if highest > highest_score :
    highest_score = highest
    exam = "Exam h"

highest = 0
i = 0
while i < len(each_exam[2]):
    if a[i] > highest:
        highest = a[i]
    i+=1
if highest > highest_score :
    highest_score = highest
    exam = "Exam a"

print(f"overall Highest mark in all exam: {highest_score} in {exam} ")
Enter fullscreen mode Exit fullscreen mode

output :

overall Highest mark in all exam: 99 in Exam h 
Enter fullscreen mode Exit fullscreen mode

All in one

q = [90,80, 67, 58, 49]
h = [87,89, 99, 47, 36]
a = [56,78, 46, 67, 69]

each_exam = [q,h,a]

highest_score = 0
exam = ""
total = 0
highest = 0
subject_position = 0
i = 0
while i < len(each_exam[0]):
    total += q[i]

    if q[i] > highest:
        highest = q[i]
        subject_position = i+1
    i+=1
if highest > highest_score :
    highest_score = highest
    exam = "Exam q"
print("Total mark in q : ",total)
print("Highest mark in q : ",highest)
print("Highest_Mark in q subject is : " , subject_position )


total = 0
subject = 0
highest = 0
i = 0
while i < len(each_exam[1]):
    total += h[i]
    if h[i] > highest:
        highest = h[i]
        subject_position = i+1
    i+=1
if highest > highest_score :
    highest_score = highest
    exam = "Exam h"
print("Total mark in h : ",total)
print("Highest mark in h : ",highest)
print("Highest_Mark in q subject is : " , subject_position )


total = 0
highest = 0
subject = 0
i = 0
while i < len(each_exam[2]):
    total += a[i]
    if a[i] > highest:
        highest = a[i]
        subject_position = i+1
    i+=1
if highest > highest_score :
    highest_score = highest
    exam = "Exam a"
print("Total mark in a : ",total)
print("Highest mark in a : ",highest)
print("Highest_Mark in q subject is : " , subject_position )

print(f"overall Highest mark in all exam: {highest_score} in {exam} ")
Enter fullscreen mode Exit fullscreen mode

5) To find Single subject average in all exam

i = 0
while i < len(q) :
    total = q[i] + h[i] + a [i]
    average = total // 3
    print("Average of each subject " , average)
    i +=1
Enter fullscreen mode Exit fullscreen mode

output :

Average of each subject  77
Average of each subject  82
Average of each subject  70
Average of each subject  57
Average of each subject  51

Enter fullscreen mode Exit fullscreen mode

Top comments (0)