1. Average of any number of scores
Write code Easy ✓ CompletedWrite a function average(*scores) that accepts any number of scores and returns their average. When it is called with no scores it should return 0.
Then call it as average(70, 80, 90) and print the result.
def average(*scores):
# return the average, or 0 when there are no scores
pass
# call average(70, 80, 90) and print the result
scores is a tuple. sum(scores) / len(scores) works, but dividing by len(scores) fails when it is 0, so check for an empty tuple first.def average(*scores):
if not scores:
return 0
return sum(scores) / len(scores)
print(average(70, 80, 90))