I am working on a code with trying to find the sum of the numbers:
-817930511,
1771717028,
4662131,
-1463421688,
1687088745
I have put them in a separate file as I should but I am confused as to why my code is not working.
#finding the sum
def main():
filename = input("Please enter your file name: ")
openthefile=open(filename,'r')
sum_number=0
for line in openthefile:
for the number in line.split(","):
sum_number=sum_number+float(numbers.strip()
print('The sum of your numbers is', sum_number)
main()
I keep getting the syntax error appearing on the 7th line of code I have changed it around some there too but can't seem to see what is wrong.
number.strip()andfor number in ...for the numberwill throw an error. That's wrong syntax. Also callingnumbers.strip()will throw NameError. You don't have any variable with the namenumbersin your code.