Solo Learn (Python for Beginners): Sum of Consecutive Numbers

Sum of Consecutive Numbers

No one likes homework, but your math teacher has given you an assignment to find the sum of the first N numbers.

Let’s save some time by creating a program to do the calculation for you!

Take a number N as input and output the sum of all numbers from 1 to N (including N).

Sample Input
100

Sample Output
5050

Explanation: The sum of all numbers from 1 to 100 is equal to 5050.

Line 1: You have to assign N as the counter variable

Line 2: This is just a comment section not an actual syntax

Line 3: This is the formula following the MDAS method.

Line 4: Will display the output of nums variable

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s