0

Sum of even

The input from the keyboard numbers are given (one at a time). You need to display the sum of all even numbers. Entry stops if an empty string ("") is entered. In any situation, when even numbers do not come across, you need to display 0 (for example, numbers were not entered at all or only odd numbers were entered). Whats wrong? https://code.sololearn.com/cmwPsgh0Ubpb/?ref=app

8th Jul 2020, 8:18 AM
Михаил
8 Respuestas
+ 9
The logic could be like this: (Slick, please check your code if an empty string is input) s = 0 while True: a = input('enter a number: ') if a == "": break elif int(a) % 2 == 0: s += int(a) print(s)
8th Jul 2020, 8:41 AM
Lothar
Lothar - avatar
+ 7
Your program has an infinite while loop
8th Jul 2020, 8:22 AM
Arnesh
Arnesh - avatar
+ 1
Just need to convert the input to a number and fix missing indentation. look here at fixed code https://code.sololearn.com/crJAos2d2DQF/?ref=app
8th Jul 2020, 8:25 AM
Slick
Slick - avatar
8th Jul 2020, 8:30 AM
Михаил
0
Lothar, if a == "" - right?
8th Jul 2020, 8:45 AM
Михаил
0
Thanks, so much.
8th Jul 2020, 8:57 AM
Михаил