It is my first post so ignore any silly mistakes.

Moving onto the topic. As it says I am going to make a python program to find the sum of first βnβ odd numbers starting with 1.

Now before you go into my while loop if you are here for quick result. Here is the easiest way to do it.

Now if you are wondering why the heck I print βsquare of numberβ, then you may need to go through basic mathematics. Alas! I am a coder man. So head to this WikiHow post.

Now coming back to problem. If you are still reading probably you also donβt like such silly and short method.

Welcome to a large solution. (Still small xD)

HA! Now comes my favourite (favorite if you are American π) part.

Step 1. We take input and convert it to integer. Cause that is string right?

Step 2. We define some variables. βiβ is iterator which will tell when we have reached βnβ numbers (If you forgot βnβ is the number of odd numbers we have to add). The βcurrentβ variable is our sum of numbers which gets updated at every loop (the loop we will write in next step). Initially set to 1, cause thatβs our first odd number in Mathematics. And finally we got our lovely variable for which we are writing this all, βsumβ. By the way it also gets updated at every loop.

Step 3. We got our very own while loop. You know what it is right. It keeps on repeating itself until its argument is true. And that argument my readers is the boolean value of β i < n β.

Now it means when i becomes equal to n, we stop our loop cause we added them. And print the result. I know what you are thinking. The inner of loop.

Here we have βsomeβ variable being incremented by the value of βcurrentβ variable. Which in first iteration is 1 (first odd number), after that we update our βcurrentβ variable to next odd number which always is +2, or am I wrong?

Next thing we do is increment our iterator cause without that you know it goes βto infinity and beyondβ.

Hope you like it, cause even if you donβt I can do nothing.

## Top comments (1)

For thought:

or sums odd numbers by

unsorted input