logo CodeStepByStep logo


Language/Type: Python file input

Consider a file called readme.txt that has the following contents:

6.7        This file has
        several input lines.

10 20    30    40


What would be the output from the code in the previous readme exercise if the for loop was modified to have a call to read and a call to split?

with open("readme.txt") as file:
    count = 0
    for s in file.read().split():
        print("input:", s)
        count += 1
    print(count, "total")

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.