Liste des Groupes | Revenir à cl c |
On 18/06/2024 13:36, David Brown wrote:No modification required ;) A read error will raise an exception; unhandled exceptions are printed to stderr along with a stack trace, and the program terminates with a failure status.#!/usr/bin/python3And here's a simple task for you. Our filesystem uses a new technology and is a bit dicey. Occasionally you will get a read error. Can you modify the python to print out that a read error has occurred?
import sys
>
if len(sys.argv) < 2 :
print("Usage: sums.py <input-file>")
sys.exit(1)
>
data = list(map(int, open(sys.argv[1], "r").read().split()))
n = len(data)
s = sum(data)
print("Count: %i, sum %i, average %i" % (n, s, s // n))
>
>
>
Les messages affichés proviennent d'usenet.