Reputation: 121
I have created a function that takes a users scores, removes the worst one (highest) adds the rest of the list together and prints the score. Beneath is the code, when I try to run this in sublime i receive no output.
def SailorsResults():
tony = []
tony = [3 ,3, 1, 1, 2, 6]
tony.remove(max(tony))
print(tony)
All i wish for this to do is take the list, remove the worst score, and add the rest up.
Upvotes: 1
Views: 3729
Reputation: 56644
If all you want is the total, you could do
def sailor_score(times):
return sum(times) - max(times)
tony = [3, 3, 2, 1, 1, 6]
print(sailor_score(tony))
Upvotes: 0
Reputation: 174485
Use sum()
to add the remaining numbers together:
def SailorsResults():
tony = [3 ,3, 1, 1, 2, 6]
tony.remove(max(tony))
print(sum(tony))
Upvotes: 2
Reputation: 9753
What you wrote is a function. To execute the code of a function, you have to call it.
For instance, in your case:
def SailorsResults():
tony = []
tony = [3 ,3, 1, 1, 2, 6]
tony.remove(max(tony))
print(tony)
SailorsResults()
Upvotes: 1