Computer Science, asked by swethayadhavfeb14, 7 months ago

sum of even numbers from 1 to 80 using python​

Answers

Answered by pehalsinghania
1

Answer:

sum = 0

for i in range (1,81):

if i % 2 == 0:

sum += i

print("sum of even numbers from 1 to 80 is", sum)

Explanation:

first we initialize a variable with the value 0 so that we can add all the even numbers to it. By using for loop we give i the value from 1 to 80. the stop value is not included so we give the value as 81. then we have an if loop to check if the value of i is even. it divides i by to and checks if the reminder is 0. if it is 0 it adds it to the variable sum. in the end we have the print statement to get the output where the value of sum is printed.

Similar questions