Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a few reasons this isn't working - but the root cause seems to be because your highestmark is started off in the wrong place. It looks like you later expect the student name and mark to be in a tuple, which is a good idea - but you never actually make this tuple anywhere. So, make one, and call it <code>highest</code> - it replaces both the <code>student</code> and <code>highestmark</code> variables. Start it as <code>None</code> instead of <code>"none"</code> (which could actually be a valid student name!), so you have above the loop:</p> <pre><code>total = 0 highest = None </code></pre> <p>and change your "is this one higher than the highest" logic to this:</p> <pre><code>if highest is None or mark &gt; highest[1]: highest = (name, mark) </code></pre> <p>Read as "if there is no highest student yet, or this one has a higher mark than the current highest, this one is the highest". Then you'll want the return to be:</p> <pre><code>return total, highest[0], highest[1] </code></pre> <p>But, since you only have a small amount of data (enough that it is feasible to have a user type it in at a console), then you can simplify this logic quite a bit. Read <em>all</em> of the data for a particular test case into a list of <code>(student, mark)</code> tuples, and then use Python's builtins to do the calculations:</p> <pre><code>def studentmarks(n): marks = [] for _ in range(n): student = input("please enter student name: ") mark = int(input("please enter mark: ")) marks.append(student, mark) return marks # Calculations marks = studentmarks(5) print('Average: ', sum(result[1] for result in marks)/len(marks)) print('Highest: ', max(marks, key=lambda s: s[1]) </code></pre> <p>Seeding it with:</p> <pre><code>&gt;&gt;&gt; marks [('Fred', 4), ('Wilma', 10), ('Barney', 8), ('Wilma', 7), ('Pebbles', 6)] </code></pre> <p>Gives an average of 7.0, and a maximum of <code>('Wilma', 10)</code>. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload