include<stdio.h>int main(){int i,x,s1=0,s2=0; while(scanf("%d",&x),x!=-1) x%2?s1+=x:s2+=x; printf("奇数之和=%d\n偶数之和=%d\n",s1,s2); return 0;}
x = int(input("从键盘输入一个正整数,加入数列中,输入'-1'时结束输入:"))if x==-1:break elif x%2==0:sum1=sum1+x list.append(x)elif x%2!=0:sum2=sum2+x list.append(x)print("list",list)print("列表中的整数和:",sum1)print("列表中的奇数和:",sum2)
import randomL = [ random.randint(1, 100) for x in range(10) ]A = [ x for x in L if not x % 2 ]B = [ x for x in L if x % 2 ]print(L)print("偶数列表:{0} 和为:{1}".format(A,sum(A)))print("奇数列表:{0} 和为:{1}".format(B,sum(B)))