dimanche 24 janvier 2016

Code for checking leap year and counting no of days in a month

This is my code:

def cal(month):
    if month in ['January', 'march','may','july','august','oct','dec']:
       print ("this month has 31 days")
    elif month in ['april','june','sept','nov']:
       print ("this month has 30 days")
    elif month == 'feb' and leap(year)== True:
       print ("this month has 29 days")
    elif month == 'feb' and leap(year) == False:
        print ("this month has 28 days")
    else:
        print ("invalid input")   


def leap(year):
    if (year % 4== 0) or (year % 400 == 0):
       print ("its a leap year!")
    else: 
       print ("is not a leap year")

year = int(input('type a year: '))
print ('you typed in :' , year)
month = str(input('type a month: '))
print ('you typed in :', month)



cal(month)
leap(year) 

The output I'm receiving:

type a year: 2013
you typed in : 2013
type a month: feb
you typed in : feb
is not a leap year
is not a leap year
invalid input
is not a leap year

Why am I not getting the output for count of days in feb if it is a 28 day month or 29?

Why am I getting the invalid input part even though its an else?

Aucun commentaire:

Enregistrer un commentaire