I was trying to create a function that added up the range of a number, including the number.
So when I input 5, I should receive 15.
Why is this function not working?
start = 0
for index in range(0,len(number)):
start += index
This could be done with a 1 liner but i'll help you out with a solution in the format that you're attempting.
def sum_nums(number): total = 0 for i in range(number + 1): total += i print total
Also, some clarification as per your error message.
len is to be used for strings. An integer does not have a length. By simply passing it to the
range function it will try all of the numbers (if you don't specify a starting number) from 1 up to that number, but not including it. That's why we do
range(number + 1) to include the target number.
Hope this helps :)