8 – Lösungen

Einführung in Python und PsychoPy

Autor

Clemens Brunner

Veröffentlicht

15. Mai 2023

Übung 1

lst = range(0, 101, 2)

with open("ue1.txt", "w") as f:
    f.write("\n".join([str(x) for x in lst]))

Übung 2

with open("ue2.txt", "w") as f:
    f.write(",".join([str(x) for x in lst]))

Übung 3

with open("sowpods.txt") as f:
    for _ in range(6):  # skip first 6 lines
        f.readline()
    counter = 0
    for line in f:
        if len(line.strip()) > 0:  # line 17563 is empty
            counter += 1

print(f"There are {counter} words in the Scrabble list.")
There are 267752 words in the Scrabble list.

Übung 4

with open("sowpods.txt") as f:
    for _ in range(6):  # skip first 6 lines
        f.readline()
    counter = 0
    for line in f:
        if len(line.strip()) > 14:
            counter += 1
            # print(line.strip())  # uncomment to see words

print(f"There are {counter} words with 15+ letters in the Scrabble list.")
There are 5757 words with 15+ letters in the Scrabble list.