OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

New to Coding: Iterating over a list in Python

  • Thread starter Thread starter Nicholas Phelps
  • Start date Start date
N

Nicholas Phelps

Guest
So I am completely new to coding and I'm going through a class right now and I'm stuck. Essentially the problem is this:

Assign sum_extra with the total extra credit received given list test_grades. Full credit is 100, so anything over 100 is extra credit.

Sample output for the given program with input: '101 83 107 90'

My current code is this:

Code:
user_input = input()
test_grades = list(map(int, user_input.split())) # test_grades is an integer list of test scores


sum_extra = 0 

for grade in test_grades: 
    if grade > 100:
        sum_extra = grade - 100
        
print('Sum extra:', sum_extra)

The problem I am having is that it isn't adding the total extra over 100. Like for the example inputs above it runs and totals 7 instead of 8. I'm honestly not sure what I am missing. Also if it isn't too much trouble, I would prefer to just get a nudge in the right direction rather than a flat out answer. Thank you so much.
<p>So I am completely new to coding and I'm going through a class right now and I'm stuck. Essentially the problem is this:</p>
<p>Assign <code>sum_extra</code> with the total extra credit received given list <code>test_grades</code>. Full credit is 100, so anything over 100 is extra credit.</p>
<p>Sample output for the given program with input: '101 83 107 90'</p>
<p>My current code is this:</p>
<pre><code>user_input = input()
test_grades = list(map(int, user_input.split())) # test_grades is an integer list of test scores


sum_extra = 0

for grade in test_grades:
if grade > 100:
sum_extra = grade - 100

print('Sum extra:', sum_extra)
</code></pre>
<p>The problem I am having is that it isn't adding the total extra over 100. Like for the example inputs above it runs and totals 7 instead of 8. I'm honestly not sure what I am missing. Also if it isn't too much trouble, I would prefer to just get a nudge in the right direction rather than a flat out answer. Thank you so much.</p>
 
Top