this is waht i am spouse to do with the function bet i keep getting the error th
ID: 3819738 • Letter: T
Question
this is waht i am spouse to do with the function bet i keep getting the error that false in not true
def append_total(filename): Given a string filename of a file containing one integers (one per line), calculate the total of all the integers and append the line "Total:" followed immediately by the integer total (no spaces in between) and ending with a newline. See example. o Assumptions: (1) file indicated by filename exists in the current directory; (2) file can be empty, and if so the sum will be 0; (3) a non-empty file can contain one or more lines ending with a newline; (4) each line contains a single integer and nothing else, and (5) the function returns None. • Examples: o append_total("f1.txt") corresponds to the files to the right
def append_total(filename):
total = 0
with open(filename) as contents:
lines = contents.readlines()
for line in lines:
if (line.isdigit()== True):
total += int(line)
else:
total = 0
final = ' Total: {} '.format(total)
add.write(final)
Explanation / Answer
def append_total(filename):
total = 0
with open(filename) as contents:
lines = contents.readlines()
for line in lines:
if (line.isdigit()== True):
total += int(line)
else:
total = 0
final = ' Total: {} '.format(total)
add.write(final)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.