2014-10-03 100 views
0

我有一個Python閏年計算器通過導入日曆+ calendar.isleap 我通過布爾做一個打印語句。但是,我的布爾總是給我一個語法錯誤。 錯誤發生在if b == False。下面的代碼。閏年與布爾值

import calendar 

def main(): 

    try: 
     a = int(input("Which year should I process? ").replace(',','.')) 
     b = calendar.isleap(a) 
     if b == False 
       print(a,"is not a leap year") 
      else: 
       print(a,"is a leap year") 
    except ValueError: 
     print("Invalid input!" 
     main() 

main() 

回答

3

你缺少一個冒號:

if b == False: 
#   ^

而且你的縮進熄滅:

if b == False 
    print(a,"is geen schrikkeljaar") 
else: # Indentation is wonky here. Check that you're not mixing tabs and spaces... 
    print(a,"is een schrikkeljaar") 

請注意,這是很奇怪的看到if be == False代碼。通常你會寫:

if not b: 
    ... 
+0

謝謝!我也修正了縮進。我現在在代碼的末尾在main()上出現了一個語法錯誤.. – Menubalk 2014-10-03 21:37:51

+0

@Menubalk - 那是因爲你在上一行缺少右括號。 – mgilson 2014-10-03 21:49:10

+0

沒關係,我找到了。失蹤 ')'! – Menubalk 2014-10-03 21:51:11