my_list.txt: 150+250 Which of the following code blocks writes the sum (400) in a new line of the file? a. with open('my_list.txt', 'r+') as file: line = file.readline() sum = 0 for i in line.split('+'): sum = sum + i file.write(str(sum)) b. with open('my_list.txt', 'r+') as file: line = file.readline() for i in line.split('+'): sum = sum + int(i) file.write(str(sum)) c. with open('my_list.txt', 'r+') as file: line = file.readline() sum = 0 for i in line.split(): sum = sum + int(i) file.write(str(sum)) d. with open('my_list.txt', 'r+') as file: line = file.readline() sum = 0 for i in line.split('+'): sum = sum + int(i) file.write(str(sum))
my_list.txt:
150+250
Which of the following code blocks writes the sum (400) in a new line of the file?
a. |
with open('my_list.txt', 'r+') as file: |
|
b. |
with open('my_list.txt', 'r+') as file: |
|
c. |
with open('my_list.txt', 'r+') as file: |
|
d. |
with open('my_list.txt', 'r+') as file: |
Trending now
This is a popular solution!
Step by step
Solved in 4 steps