> 其他 >
用python做一个判断多个数字是否为偶数或奇数的程序
用python做一个判断4个数字是否为偶数或奇数的程序,并且在最后说出1.奇数的数目比偶数多 2.偶数比奇数多 3.奇数和偶数一样多
人气:395 ℃ 时间:2019-11-07 07:05:57
解答
datas = [1,2,3,4]
s = d = 0
for i in datas:
    if i%2 == 0:
        d+=1
    else:
        s+=1
if s > d:
    print '奇数多'
elif s < d:
    print '偶数多'
else:
    print '一样多'
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版