HW: Files & While

In this HW you will create 3 programs that get input/output from files and use while loops.

Rx: <15 min Av: 15-30 min Sd: 30-45 min DNF: 45+ min

while.py

Create a program while.py that allows the user to enter in a list of numbers, prints them out in sorted order, and prints the sum of the numbers. Prompt the user to continue entering numbers, and enter the number ‘0’ when finished.

Hints:

count.py

Write a program count.py that reads in the file turing.txt and counts the number of occurrences of the word “the”.

Hints:

Recommended Development Steps:

  1. Download turing.txt & put it in the same folder as count.py.
  2. Read in the file & print it out (either line by line or as one big string)
  3. Print out the number of ‘the’s using the count function, OR complete the following steps.
  4. Print the line split on spaces.
  5. Print just a word on each line.
  6. Only print out “the”.
  7. Count the number of times you see “the” (create a variable or a list) and print it out.

lines.py

Write a python program that reads 3 files, called text1.txt, text2.txt, and text3.txt, counts the number of lines in each file, and prints out the number of lines to a file counts.txt. Each line of counts.txt should look like [filename] : [the number of lines in the file].

Hints:

Recommended Development Steps:

  1. Create 3 text files
  2. Make a list of the filenames
  3. Make a loop to print each file
  4. Modify your loop to print the number of lines
  5. Output the number of lines to counts.txt instead