Python问题 第一题 请编写程序输出奇偶数月份。 原题为educoder上控制程序一? Python问题 原题为educoder上控制程序一 1^2...

Python\u95ee\u9898 \u539f\u9898\u4e3aeducoder\u63a7\u5236\u7a0b\u5e8f\u4e00\uff1f

\u8fd9\u91cc\u7684\u63a7\u5236\u5668\u662f\u975e\u5e38\u597d\u7684\uff0c\u63a7\u5236\u7a0b\u5e8f\uff0c\u8fbe\u5230\u4e00\u5b9a\u6807\u51c6\u3002


if (month<=7 and month%2!=0) or (month>=8 and month%2==0):
print("yes")
else :print("no")
你的变量a没被赋予month的值,所以用month 不用a
刚才填了个行尾 : 亲测可运行。你还可以更严谨一点儿
比如month >=1 and month <=7 或 month>=8 and month<=12之类
比如:
if (month>=1 and month<=7 and month%2!=0) or (month>=8 and month<=12 and month%2==0):
print ("yes")
else:print("no")
或者楼下那种缩写:
if(1<=month<=7 and a%2!=0) or (8<=month<=12 and month%2==0):
...

####### begin #######

if (a<=7 and a % 2) or (8<= a<=12 and not a % 2):
print ("yes")
####### end #########
# 如果不是31天的月份,输出no
####### begin #######

if (a<=7 and not a % 2) or (8<= a<=12 and a %2):
print ("no")
####### end #########

if (month<=7 and month%2==1) or (month>7 and month%2==0):print ("yes")
else:print("no")

扩展阅读:扫一扫一秒出答案 ... python 字典 集合 ... python 列表 集合 ... python 考试题 带答案 ... python 文化 示例 ... python &用法 ... 扫一扫题目出答案 ... python 类 实例 ... python面试题及答案 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网