Esercitazione #2
Lezione 11 di 12 del corso Gestione dei file in Python di Coddy.
Sfida
MedioScrivi una funzione chiamata average_word_length che riceve un nome di file come argomento e restituisce la lunghezza media delle parole (arrotondata a due cifre decimali) nel file.
Per esempio,
Se input1.txt contiene:
The quick brown fox jumps over the lazy dog. The dog barks, and the fox runs away.
Allora average_word_length('input1.txt') restituisce 3.71
Nota: rimuovi tutta la punteggiatura!
Provalo tu
def average_word_length(filename):
# Scrivi il codice quiTutte le lezioni di Gestione dei file in Python
Esercitati da solo: Compilatore Python online