여러 행으로 목록을 추가해야하는이 문제를 해결하려고합니다. 하지만 해결책을 찾지 못했습니다.Python - 여러 행의 목록 합계
코드 :
g = input("Enter the file name:")
infile = open(g,'r')
counter = 0
for lu in infile:
lu = lu.strip()
lulu = lu.split(",")
lulu = [float(i) for i in lulu]
coo = sum(lulu)
print("The sum of your numbers is " + str(coo) + ".")
전류 출력 :
Enter the file name:nums.txt
[-2.5, 2.0]
[8.0]
[100.0, 3.0, 5.1, 3.7]
[6.5]
The sum of your numbers is 6.5.
예상 출력 : 루프에서
Enter the file name:nums.txt
[-2.5, 2.0]
[8.0]
[100.0, 3.0, 5.1, 3.7]
[6.5]
The sum of your numbers is 125.8.
아, 내가 볼! 도와 주셔서 감사합니다! –