CoCalc Shared Fileslab8.ipynbOpen in CoCalc with one click!
Authors: Laura Arias Fernandez, Ngawang Lobsang, Murat Must, Zoƫ Wentzel
Views : 17
In [13]:
print("whatsup")
whatsup
In [49]:
def wordcount(fname): try: myfile = open(fname) filestring = "" count = 0 for word in myfile: filestring = filestring + word strippedstring = filestring.split() for string in strippedstring: count += 1 except FileNotFoundError: print("Bad file name") count = -1 print(count) wordcount('test.txt')
7
In [ ]:
In [125]:
import random import string def make_data(fname): newfile = open(fname,"w") for i in range(1,1001): newfile.write(str(i)) newfile.write(",") newfile.write(str(random.randint(-1000,1000))) newfile.write("\n") newfile.close() make_data('data.csv') f = open('data.csv') stringdata = f.read() ## print(stringdata) f.close() def read_data(fname): try: myfile = open(fname) f = open(fname) min = 1000 max = -1000 listoflines = f.readlines() count = 1 for line in listoflines: num = line num = num.strip("\n") num = num.split(",") if int(num[1]) < min: min = int(num[1]) elif int(num[1]) > max: max = int(num[1]) except FileNotFoundError: print("Bad file name") print(min) print(max) read_data('data.csv')
-998 996
In [ ]:
In [ ]: