Hi @byteslayer80073 ,
To overcome the SyntaxError
, you would not indent the second elif
block. You could instead further indent this statement, however, your function would still not produce a correct solution:
return sumlst
Since you have already revised your code, letâs consider what you have now. The instructions include this:
The function should sum the elements of the list until the sum is greater than 9000
.
Accordingly, if the sum has reached exactly 9000
and there still are additional items in the list that was passed to it, we need to continue at least to the next item.
What does the current version of your function compute if we call it as follows?:
print(over_nine_thousand([7000, 2000, 4000, 6000]))
The correct result would be 13000
.
As you continue to work on your function, you could simplify it quite a bit. For example, you do not need to check for an empty list, as it is not a special case. In fact, these two blocks are both unnecessary:
if len(lst) == 0:
return 0
elif sumlst < 9000:
sumlst = sumlst + num
If you eliminate them, youâll need to change this to an if
header:
elif sumlst > 9000:
Edited on August 24, 2019 to add the following:
This statement, of course, still has an important role to play in a working solution:
sumlst = sumlst + num