python - Having trouble creating a function that takes one argument, and returns a result of adding odd numbers between 1 and argument? -
so far have this...
def sumofodds(n): result = 0 in range(1, n+1, 2): result = result + print(result)
this gives me sum, prints numbers come before it. need sum, not rest of values.
you can use loop , range()
2 step
sum = 0 max = 11 in range(1, max, 2): # not including max sum += print sum #out:25 (1 + 3 + 5 + 7 + 9)
Comments
Post a Comment