+ 3
‘That’s Odd’ Python help
#receive user input and store in list ‘nums’ nums = list(map(int, input().split())) #store even numbers from nums evens = [x for x in nums if x % 2 == 0] #add together all the even numbers print(sum(evens)) Could anyone PLEASE tell me why this wouldn’t be working?? I cannot for the life of me figure out what I’m doing wrong... as far as I can tell the only output I’m getting is “0”
13 Respuestas
+ 5
num = int(input())
even = 0
value = 1
while value <=num:
value += 1
x = int(input())
if x % 2 == 0:
even += x
print(even)
+ 4
Each number is input on a new line not all on the same line.
+ 4
lenth = int(input())
a = 0
total = 0
while a<lenth:
i = int(input())
if i%2==0:
total+=i
a+=1
print(total)
for explanation dm me
no offense
i can explain better there...
cuzz comment box conversation is silly
+ 2
ChaoticDawg so what parameter would i need to put inside split() for it to see ‘enter’ or ‘new line’ as the delimiter?
+ 2
split takes all whitespace as delimiter.
However, the input function goes always until the next newline only.
So for this code, you have to enter all numbers in one line.
+ 1
You need to loop to input N times
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)
}
""""
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)
}
""""
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);
}
""""
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
nums=[]
ans=0
range_of_nums=int(input())
while 1:
try:
nums.append(int(input()))
except EOFError:
break
for i in range(range_of_nums):
if nums[i]%2==0:
ans+=nums[i]
print(ans)