python中判断x是奇数的表达式_奇数的Python逻辑测试

该程序用于检查三个数x、y和z是否为奇数,并找出其中的最大奇数。通过使用取模运算符%来判断每个数的奇偶性,然后根据条件进行比较,输出最大的奇数。
摘要由CSDN通过智能技术生成

我想知道我下面的答案是正确的和可行的还是有什么改进谢谢。

问题:一个程序检查x y和z是否奇数或偶数是否为奇数的程序检查这三个数中的最大值。

下面是我的答案:x = 4

y = 7

z = 9

#first condition where 3 numbers are all odd.

if x%2 == 1 and y%2 == 1 and z%2 == 1:

if x > y and x > z:

print "x is the biggest odd number."

elif x > y and z > x:

print "z is the biggest odd number."

else:

print "y is the biggest odd number."

#second condition where 2 of the numbers are odd

elif x%2 == 0 and y%2 == 1 and z%2 == 1:

if y > z:

print "y is the biggest odd number."

else:

print "y is the biggest odd number."

elif x%2 == 1 and y%2 == 0 and z%2 == 1:

if x > z:

print "x is the biggest odd number."

else:

print "z is the biggest odd number."

elif x%2 == 1 and y%2 == 1 and z%2 == 0:

if x > y:

print "x is the biggest odd number."

else:

print "y is the biggest odd number."

#third condition where only one of the numbers is odd.

elif x%2 == 0 and y%2 == 0 and z%2 == 1:

print "z is the biggest odd number."

elif x%2 == 1 and y%2 == 0 and z%2 == 0:

print "x is the biggest odd number."

elif x%2 == 0 and y%2 == 1 and z%2 == 0:

print "y is the biggest odd number."

#last condition if none of the numer are odd or not numbers.

else:

print " None of the numbers are odd or not a number."

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值