← Back to challenges

Sum of the Odd Numbers

PythonMediummathloops

Instructions

Create a function which returns the total of all odd numbers up to and including n. n will be given as an odd number.

Examples

add_odd_to_n(5) ➞ 9
# 1 + 3 + 5 = 9

add_odd_to_n(13) ➞ 49

add_odd_to_n(47) ➞ 576

Notes

Curiously, the answers are all square numbers!

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Valid Variable Names