Exercise 8 

Write a program in Python that asks the user to enter an integer n and display the value of the sum 1 + 2 + ... + n = ?

Solution

# Ask to type a value of the integer n
n = int(input("Type a value of the integer n "))
# define and initialize an auxiliary integer j
j = 0
for i in range(1,n+1):
j = j + i
print("The sum 1 + 2 + 3 + ...+ n = : ", j)
Younes Derfoufi
One thought on “Solution Exercise 8”

Leave a Reply