total = 0
>with open('/Users/richarddillon/Desktop/numbers.txt', 'r') as infile:
> for line in infile:
> total += float(line)
>print(total)
>
>
>Python returned "ValueError: could not convert string to float: "
>
>That means some of your lines are not floats - are there any blanks?
You can find out by inserting a print line:
with open('/Users/richarddillon/Desktop/numbers.txt', 'r') as infile:
for line in infile:
print('Line = ', line)
total += float(line)
And see what the offending line looks like.
Once you know what the error is caused by you can add a line
or two to avoid (or handle) the problematic cases.
Alan G.
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor