Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ITERATIVE SUM FUNCTION
- n = int(input("Enter the number of addends in your sum: "))
- def sum_iterative(n):
- if n == 1:
- return "The answer is 1."
- elif n == 0:
- return "The answer is 0."
- elif n < 0:
- return "False argument"
- else:
- sum = 0
- for i in range(1, n + 1):
- sum += i
- return "The answer is " + str(sum) + "."
- print(sum_iterative(n))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement