Answer to Question #43981 in Python for Gwen

Question #43981
Write a program that repeatedly asks a user to enter a number. The program will sum up all the even number that the user keyed in. Terminate the program when the user enters -10, and display the sum of all the EVEN numbers entered by the user (exclude -10). Please help the part, I have no idea how to do the sum of even number. But, other than that, I am able to do. Thank you.
Expert's answer
number_list = []
while True:
number_list.append(int(raw_input("Enter Number: ")))
if number_list[-1] == -10:
break

s = 0 #sum
for i in number_list[:-1]:
if i % 2 == 0:
s += i

print "Sum of all the even numbers ", s

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS
paypal