Python Program Not Reading in File -
trying create simple program counts number of lines, words, , characters in file. can't seem file read in though, returns name of file , not contents of file. have been passing file name in on command line without quotation marks.
print("this program count number of line, words, , characters in file.") user_in = input("please enter file counted: ") infile = open(user_in, "r") lc = 0 wc = 0 w_len = 0 line in infile: usr_list = user_in.split(" ") print(usr_list) lc += 1 x in usr_list: w_len += len(x) wc += 1 #avg = w_len//wc print("there {} lines, {} words, , {} characters in file.".format(lc, wc, w_len)) infile.close()
you're doing usr_list = user_in.split(" ")
seems like usr_list = line.split(" ")
Comments
Post a Comment