2016-02-04 34 views
1

我是比較新的蟒蛇。我想製作一個程序來檢查日期是否有效。我寫了功能代碼來檢查迄今爲止的閏年。但是我想融入更大的程序來檢查月份和日期的有效性。我怎樣才能在最後一行說:「當C爲真繼續具有一定的if else邏輯(...的代碼,我將在後面寫)」和「當C爲假繼續這個其他的if else邏輯」Python中,真/假,功能集成到程序

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) 

回答

0

這可能是你在找什麼。記住

if(c): # Checks if C is True, 
    then… # If so, it gets in 
return … # Otherwise, it goes other way 

讓您leap_year功能,必須在奧德返回的東西,使這項工作

1

您可以使用關鍵字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")