0
How can plus 1 to 100 odd number (use for i in range(1,101))
sum=0 for i in range(1,101): sum=sum+i
6 Respostas
+ 2
sum([i for i in range(1, 101) if i % 2])
+ 2
use
if(i%2 !=0)
sum = sum + i;
@abhishek
+ 1
for (i=1;i<=100;i++)
{
if (i%2!=0)
sum=sum+i;
}
This code is for C language
+ 1
is it ok to use (i%2==1) instead of (i%2!=0)??
+ 1
print(sum( [ i for i in range(1,100,2)]))
0
sum = 0
for i in range(1,101):
if (i % 2 != 0):
sum = sum + i
print(sum)