115k views
0 votes
Where is the error? sum the numbers from start to end, both ends being inclusive

def main():
-> start = int(input())
-> end = int(input())
-> total = 0
-> for i in range(start, end, 1):
--> total = total + i
-> print (total)
main()

User Mbwasi
by
8.1k points

1 Answer

2 votes

Final answer:

The error in the given code is that the closing parenthesis is missing at the end of the print statement. It should be print(total) instead of print (total). The code should also be properly indented.

Step-by-step explanation:

The error in the given code is that the closing parenthesis is missing at the end of the print statement. It should be print(total) instead of print (total). The code should also be properly indented.

Here is the corrected code:

def main():
start = int(input())
end = int(input())
total = 0
for i in range(start, end+1):
total = total + i
print(total)

main()

This corrected code will sum the numbers from the start to the end, both ends being inclusive.

User SJR
by
8.5k points