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
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:
sum
function allows you to sum a list of numbers.I recommend following the sentinel while loop pattern:
value = initialize
while value != sentinel:
process value
value = updated value
Write a program count.py
that reads in the file turing.txt
and counts the number of occurrences of the word “the”.
Hints:
split
function allows you to split a line of input into a list of words by splitting the line on spaces.count
function allows you to count the number of occurrences in a string or list.Recommended Development Steps:
turing.txt
& put it in the same folder as count.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:
text1.txt
, text2.txt
, and text3.txt
to a list, so you don’t have to copy & paste your code.Recommended Development Steps:
counts.txt
instead