在命令行上执行时,它应该有 python3 a4.py apple
我试图对其数字求和的文件看起来完全像这样
4 14
5
这是我到目前为止收集到的
import sys
print(sys.argv[1])
fp = open(sys.argv[1])
fileContents = fp.read()
fp.close()
numbers = fileContents
print(numbers)
def map(f,items):
result = []
for i in range(0,len(items),1):
result = result + [f(items[i])]
return result
a=map(eval,numbers)
def sum(num):
total = 0
for i in range(0,len(num),1):
total = total + i
return total
print(sum(a))