Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
For marks = {"Asha": 72, "Ravi": 85, "Meera": 64, "Kabir": 90}, find the name with the highest mark.
Keep the best so far, and compare each new value with it.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
Plan. Keep the best name and the best mark so far. Go through the pairs. If a mark is higher than the best, replace both.
| Pair | Best so far |
|---|---|
| Asha 72 | Asha, 72 |
| Ravi 85 | Ravi, 85 |
| Meera 64 | Ravi, 85 |
| Kabir 90 | Kabir, 90 |
Answer: Kabir, with .
Log in to join the discussion.
Loading…