Issue
I'm trying to write a function where the user gives the start and end of a range and the output is that range summed. This is my best try:
def sum_range (start, end):
output = 0
userange = range(start, end)
for i in userange :
sum(i, output)
return output
I get the following error:
TypeError: 'int' object is not iterable
Solution
you can do :
def sum_range(start, end):
return sum(range(start, end))
example :
>>> def sum_range(start, end):
... return sum(range(start, end))
...
>>> sum_range(10,14)
46
Answered By - Dadep
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.