Python 2 Repeating Question

Asked 2 years ago, Updated 2 years ago, 117 views

I'm learning based on Python 2! (I don't know why I'm learning it the old way.)The code I made for this problem is as below, but I don't know what's wrongPlease give strength to Python beginners!

python-2.7 loops errorcode

2022-09-21 18:01

1 Answers

Use random to get a random score.

import random

scores = (random.randint(1, 100) for _ in range(10))

def getAverage(values):
    def sumAverage(scores): return float(scores[0]) + sumAverage(scores[1:]) if scores else 0
    return sumAverage(values) / len(values) if len(values) > 0 else None

print(getAverage(sorted(scores)[1:]))


2022-09-21 18:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.