我需要让用户输入一定数量的数字(5),并将它们存储在一个文本文件中。 我还需要找出这些数字的平均值。我会用求和函数除以5吗?你知道吗
这是针对python的,我在osx上使用空闲的3.4版本
lst = list() #creates a list to later store nubers in
def addtolist(): #creates a function for adding numbers to the list
def listcount(): #
try:
lst.append(int(input("Enter a number:")))
except ValueError:
print("That was not a number")
print(lst)
listcount()
yes = ["yes", "y"]
no = ["no", "n"]
yup = ["yes", "y"]
nah = ["no", "n"]
enteragain = input("Enter another number? yes/no")
if enteragain in yes:
print("Ok")
elif enteragain in no:
print("We'll try again")
addtolist()
runagain = input("Are those the numbers you wanted to enter?")
if runagain in yes:
print("Ok")
elif runagain in no:
print("We'll try again")
addtolist()
addtolist()
我对它做了一点修改,并没有将列表存储为文本文件,而是决定以列表的形式保存它。下面是我在最后得出的结论:
相关问题 更多 >
编程相关推荐