Answer:
total = 0
n = int(input("Enter a number: "))
for i in range(1, n+1):
total += i
if (n * (n + 1) / 2) == total:
print("Values are the same")
else:
print("Values are different")
Step-by-step explanation:
I believe the series you wrote should be 1+2+3 ... +(n-1)+n.
The sum of the natural numbers up to n can be calculated as n(n+1)/2.
The code is written in Python.
Initialize a variable total to hold the total
Ask the user for input, n
Create a for loop that iterates from 1 to n
Add all the numbers in the range to the total
When the loop is done, check if the total is equal to given formula. If they are equal, print same.Otherwise, print different