+ 3
That's odd
2nd pass other fail len = int(input()) sum = 0 for i in range(len): num = int(input ()) if num % 2 == 0: sum = sum +num print(sum)
8 ответов
+ 8
input() does not work in loops in sololearn, all should be given as soon as the program starts running.
+ 2
I solved it
+ 1
num=int(input())
sum=0
for i in range(num):
num=int(input())
if (num%2!=0):
sum=sum+num
print(sum)
""""
int sum = 0;
for(int i=0;i<=num;i++)
{
if(num%2!=0)
{
sum=sum+num;
print(sum)
}
}
""""
int sum = 0;
int i= 0;
while(num%2!=0)
{
sum=sum+num;
i=i+1;
print(sum);
}
""""
0
Your error is that you are printing the local value of the var sum so it will repeat the value everytime the loop find a even number.
Reorder your code like this:
len = int(input())
sum = 0
for i in range(len):
num = int(input ())
if num % 2 == 0:
sum = sum +num
print(sum)
0
This is how i did it.
List = []
n = int(input())
for i in range(0, n):
ele = int(input())
List.append(ele)
t = [num for num in List if num % 2 ==0]
print(sum(t))
0
num=int(input())
sum=0
for i in range(num):
num=int(input())
if (num%2!=0):
sum=sum+num
print(sum)
""""
int sum = 0;
for(int i=0;i<=num;i++)
{
if(num%2!=0)
{
sum=sum+num;
print(sum)
}
}
""""
int sum = 0;
int i= 0;
while(num%2!=0)
{
sum=sum+num;
i=i+1;
print(sum);
}
""""
0
num=int(input())
sum=0
for i in range(num):
num=int(input())
if (num%2!=0):
sum=sum+num
print(sum)
""""
int sum = 0;
for(int i=0;i<=num;i++)
{
if(num%2!=0)
{
sum=sum+num;
print(sum)
}
}
""""
int sum = 0;
int i= 0;
while(num%2!=0)
{
sum=sum+num;
i=i+1;
print(sum);
}
""""
0
num=int(input())
sum=0
for i in range(num):
num=int(input())
if (num%2!=0):
sum=sum+num
print(sum)
""""
int sum = 0;
for(int i=0;i<=num;i++)
{
if(num%2!=0)
{
sum=sum+num;
print(sum)
}
}
""""
int sum = 0;
int i= 0;
while(num%2!=0)
{
sum=sum+num;
i=i+1;
print(sum);
}
""""