-3
Array_student = [Joe, Peter, Andy, Tom, Pat]

Array_marks = [14, 9, 6, 8, 12]

Find the highest marks in the array and print the name of the student with the highest marks.

Without using any function such as max().

  • You may want to explain the reason why you don't want to use any function at all (even not the [built-in ones](https://docs.python.org/3/library/functions.html)) as well as show what you have tried and where you have a specific problem. – MagnusO_O Sep 18 '22 at 11:46
  • What have you attempted so far? – j_b Sep 18 '22 at 12:44

2 Answers2

0

You should use {} dict where the student name will be the key and the marks will be the value and then use sorting and take the first item of the new list

data = {'joe':14, 'Peter': 9, 'Andy': 6, 'Tom' : 8, 'Pat' : 12}
sort_data = sorted(data.items(), key=lambda x: x[1], reverse=True)
next(iter(sort_data)) # outputs 'Peter'
Mr_yassh
  • 29
  • 4
0
Array_student = ["Joe", "Peter", "Andy", "Tom", "Pat"]
Array_marks = [14, 9, 6, 8, 12]

greatest_point = 0
greatest_student = ""
for idx,mark in enumerate(Array_marks):
    if mark > greatest_point:
        greatest_point = mark
        greatest_student = Array_student[idx]
print(greatest_student) #Joe
uozcan12
  • 404
  • 1
  • 5
  • 13