CBSE Class 11 Informatics Practices Question 61 of 75

Conditional and Looping Constructs — Question 33

Back to all questions
33
Question

Question 17

WAP to display the sum of the given series:

Sum = 1 + (1 + 2) + (1 + 2 + 3) + (1 + 2 + 3.....n)

Solution
n = int(input("Enter the value of n: "))

sum = 0
for i in range(1, n + 1):
    for j in range(1, i + 1):
        sum += j

print("The sum of the series is:", sum)
Output
Enter the value of n: 4
The sum of the series is: 20
Answer