我对 python 比较陌生。我想制作一个程序来检查日期是否有效。到目前为止,我编写了函数代码来检查闰年。但我想集成到更大的程序中来检查月份和日期的有效性。我怎么能在最后一行说“当 C 为 true 时继续执行某个 if else 逻辑(...我稍后将编写的代码)”和“当 C 为 false 时继续执行另一个 if else 逻辑”
def leap_year(c):
if c % 4 == 0 and y % 100 != 0:
print("True (Non-Centurial)")
else:
if c % 400 == 0:
print("True (Centurial)")
else:
print("False")
pass
for c == True:
...(my if else statements)
最佳答案
您可以使用 elif
关键字实现 if-else 结构:
if c % 4 == 0 and y % 100 != 0:
print("True (Non-Centurial)")
elif c % 400 == 0:
print("True (Centurial)")
elif condition1:
pass
elif contition2:
pass
else
print("False")
关于Python,True/False,将函数集成到程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35210132/