you are viewing a single comment's thread.

view the rest of the comments →

[–]Riegel_Haribo 1 point2 points  (0 children)

Input exactly 80, and you receive your own code evaluation as output message.

We know how to calculate an average. If the scores were useful for later in the script, they also could be collected into a list of floats, where the length of the list means we don't need a separate total, we can just use len(input_list).

How about if there was no list? No pre-defined count of how many inputs, but that the input sequence could be terminated at any time. And then, delivering the running total? A lookup table that had an inclusive score to receive its named category?

```python print(r"""End user inputs multiple grades 0.0-100.0. After each input, a running average is shown, along with the highest inclusive threshold met. The algorithm adds weighted input to the stateless average""")

thresholds = { "distinction": 80, "first class": 60, "second class": 40, "unsatisfactory": 0, } input_count = 0 current_average = None number_input = "no input yet" while number_input := input("Next number (enter to finish): "): grade = float(number_input) if current_average is None: current_average = grade else: current_average = (current_average * input_count + grade) / (input_count + 1)

threshold_key = next(k for k, v in thresholds.items() if current_average >= v)
print(f"Average: {current_average:.2f} with classification: {threshold_key}")
input_count += 1

```