Hint
Not sure how to start?
First, ask the user for the start and end of the range using input()
and convert them to integers:
start = int(input("Enter the start of the range: "))
end = int(input("Enter the end of the range: "))
Next, write a simple function that adds up all the numbers from start
to end
:
def sum_range(start, end):
total = 0
for num in range(start, end + 1):
total += num
return total
Finally, call your function and print the result:
print(sum_range(start, end))
Remember: range(start, end + 1)
makes sure the end
number is included in the sum.