Aug-21-2020, 08:40 AM
Hi everybody!
I wrote this code to return the number of days for a given couple of months / day
my function must take into consideration leap years for the calculation of the number of days in the month of February
So my function should return none if the arguments don't make sense
This is the code
at the beginning I did not enter the parentheses for the number of days (30/31/29/28) for the print function, I had this error
File "main.py", line 6
print 30
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print (30)?
*********************************
then I add the parentheses and I got this error
File "main.py", line 8
elif month in ['January', 'March', 'May', 'July', 'August', 'October', 'December']:
Can you help me please, how can i solve this issue??
I wrote this code to return the number of days for a given couple of months / day
my function must take into consideration leap years for the calculation of the number of days in the month of February
So my function should return none if the arguments don't make sense
This is the code
def isYearLeap(year): return year % 4 == 0 and (year % 400 == 0 or year % 100 != 0) def daysInMonth(year, month): if month in ['September', 'April', 'June', 'November']: print 30 elif month in ['January', 'March', 'May', 'July', 'August','October','December']: print 31 elif month == 'February' and isYearLeap(year) == True: print 29 elif month == 'February' and isYearLeap(year) == False: print 28 else: return None testYears = [1900, 2000, 2016, 1987] testMonths = [2, 2, 1, 11] testResults = [28, 29, 31, 30] for i in range(len(testYears)): yr = testYears[i] mo = testMonths[i] print(yr, mo, "->", end="") result = daysInMonth(yr, mo) if result == testResults[i]: print("OK") else: print("Failed")[/quote]NB:
at the beginning I did not enter the parentheses for the number of days (30/31/29/28) for the print function, I had this error
File "main.py", line 6
print 30
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print (30)?
*********************************
then I add the parentheses and I got this error
File "main.py", line 8
elif month in ['January', 'March', 'May', 'July', 'August', 'October', 'December']:
Can you help me please, how can i solve this issue??