Below is my code. It will ask the user for their input. After putting in the required input and pressing enter it ends and doesn't go to the required function to execute. If someone could help me fix it, I would be most appreciative.
from statistics import mean #headOfFile - prints the first 5 lines of the file passed in as a parameter def headOfFile(myFile): return headOfFile f=open("textFile.txt", "r") for i in range(5): f.readline(5) print (i) f.close() #tailOfFile - prints the last 5 lines of the file passed in as a paramete def tailOfFile(myFile): return tailOfFile f=open("textFile.txt","r") for i in range(5): f.readline(-5) print (i) f.close() def wordCount(myFile): return wordCount f=open("textFile.txt", "rt") words = "textFile.txt".split() print ('Number of words in text file: ', len(words)) file = open("textFile.txt", "r") lines = "textFile.txt" f.readline() print ("Number of lines in text file: ", len(lines)) f.close() #stats - prints the smallest, largest, and average of the numbers in the file def stats(myFile): return stats f=open("number.txt", "r") l=[ int(l) for l in input("number.txt").split(",")] minl = l[0] for i in range(len(l)): if l[i] < minl: minl = l[i] print ("The smallest number in the list is: ",minl) maxl = l[0] for i in range(len(l)): if l[i] > maxl: maxl = l[i] print ("The largest number in the list is: ", maxl) Average = sum(l) / float(len(l)) my_list = ("number.txt") average =Average(my_list) print ("Average of list is: ", average) f.close() myFile = input("Enter the name of the first file you want to use(headOfFile, tailOfFile, wordCount, stats): ") headOfFile(myFile) tailOfFile(myFile) wordCount(myFile) https://stackoverflow.com/questions/67259665/python-code-with-several-functions-asks-user-for-input-after-input-code-ends April 26, 2021 at 09:04AM
没有评论:
发表评论