大佬教程收集整理的这篇文章主要介绍了具有多个功能的 Python 代码,要求用户输入,输入后,代码结束且不执行,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
下面是我的代码。它会询问用户的输入。输入所需的输入并按回车键后,它结束并且不会去执行所需的功能。如果有人能帮我修复它,我将不胜感激。
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)
您的函数都以 return
语句开头,出于某种原因只是返回对函数本身的引用。因此这些函数没有做任何有用的事情,因为它们的其余代码都不会被执行。
以上是大佬教程为你收集整理的具有多个功能的 Python 代码,要求用户输入,输入后,代码结束且不执行全部内容,希望文章能够帮你解决具有多个功能的 Python 代码,要求用户输入,输入后,代码结束且不执行所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。