Csci 1020 March 5, 2023 Program Assignment 9: 'Data Science'

There are 5 little program below which work with plain text files. You can download these little programs, or you can copy and paste these into the IDLE editor.

You can download all these here: src/

Write a program which creates a file containing 10000 numbers, then write a program which reads that file then prints out the sum of the numbers.

Modify the program to create 10000 numbers between 1 and 100, then find the sum of these.
# : create text file of random numbers
import random
f = open('numbers.txt', 'w')
for i in range(10000):
   n = random.randint(1,10)
   f.write( str(n) + "\n")
# : add up the integers in a text file
g = open('numbers.txt',errors='ignore')
sum = 0
while True:
   n = g.readline()
   if n == '':
   sum = sum + int(n)
print("The sum is", sum)

Download the file: pop_county_state.csv

Find the population of Carlton County, MN by year.

Q: Find the population of Hennepin County, MN in 2019.
# : find Carlton County population by year, and 2020
g = open('pop_county_state.csv',errors='ignore')
while True:
	line = g.readline()
	if line == '':
	if "Carlton County, MN" in line:
		line = line.replace('"','')
		field = line.split(',')
		print(field[5],':', field[6])
		if field[5] == "2020":
			print("In year 2020, Carlton County has ",field[6]," residents.\n")

Download the file: city_lat_lon.txt

Find the lat/lon of Duluth,MN

Find the lat/lon of Minneapolis,MN
# : find City lat/lon
g = open('city_lat_lon.txt',errors='ignore')
while True:
	line = g.readline()
	if line == '':
	if "Duluth,MN" in line:
		code,lat,lon,name = line.split()
		print("The 3 letter code for ", name," is ", code,"\n")

Download the file: oz.txt

Count the occurences of the word "the" in the book.

Count how many times Dorothy and Toto occur in the book
# : count a word in a text
word = "the"
g = open('oz.txt',errors='ignore')
s =
s = s.lower()
print(word," occurs this many times:", s.count(word))

Content is neither approved nor reviewed by FDLTCC.