write a program in python to find sum of first 10 even number ( using while statement )
Answers
# Python3 implementation to find sum of
# first n even numbers
# function to find sum of
# first n even numbers
def evensum(n):
curr = 2
sum = 0
i = 1
# sum of first n even numbers
while i <= n:
sum += curr
# next even number
curr += 2
i = i + 1
return sum
# Driver Code
n = 20
print("sum of first ", n, "even number is: ",
evensum(n))
Answer:
write a program in python to find sum of first 10 even number ( using while statement )
Answer:
def even_sum(n):
sum = 0
i = 2
while i <= n:
sum += i
i = i + 2
return sum
n = int(input('Enter any number: '))
print("Sum of all even numbers from 1 to", n , "is: " , even_sum(n))
Explanation:
in the above answer, we have define a function by using a keyword def and the name of the function is even_sum() this function accepting a value as a argument this specific the range or number from 1 to number n , inside this function we create a variable sum= 0 , i = 2 sum or adding the value and i for even numbers and a while loop in which we are comparing the variable and at last we function returns the sum of the even numbers
To know about more click here,
brainly.in/question/18905944
To know about more click here,
brainly.in/question/16088081
#SPJ2