Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News Sign UpSign In
| Download
Views: 151
Kernel: Python 3 (system-wide)
print("whatsup")
whatsup
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
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