Computer Science, asked by suvangipatra08193, 21 days ago

write a program in python to accept any 15 numbers and print the sum of even numbers only​

Answers

Answered by Equestriadash
0

Co‎de:

\tt l\ =\ list()\\for\ i\ in\ range(15):\\{\ \ \ \ \ }n\ =\ int(in put("Enter\ a\ number:\ "))\\{\ \ \ \ \ }l.append(i)\\s\ =\ 0\\for\ i\ in\ l:\\{\ \ \ \ \ }if\ i\%2\ ==\ 0:\\{\ \ \ \ \ }{\ \ \ \ \ }s\ =\ s\ +\ i\\print(s,\ "is\ the\ sum\ of\ the\ numbers\ entered.")

Explanation:

We create a list for the numbers that are going to be entered. A \tt for loop is initiated, that runs 15 times, obtaining 15 numbers from the user. As the numbers are being entered, they're being added to the list earlier created for the same, by the \tt append() function. We then create a variable 's', that is going to represent the sum of the even numbers in the list. Another \tt for loop initiated, that traverses through the list and checks if the numbers are even or not, using a conditional statement. If they're even, they get added to 's'. The final output is printed in an appropriate \tt print statement.

Similar questions