Write a program to print the dates of all the Sundays in a given year in python
Code
# Write a program to print the dates of all the Sundays in a given year.def dates_of_sundays(year):import datetimefor month in range(1, 13):for day in range(1, 32):try:date = datetime.date(year, month, day)except ValueError:continueif date.strftime("%A") == "Sunday":print(date.strftime("%d/%m/%Y"))if __name__ == '__main__':year = int(input("Enter the year: "))dates_of_sundays(year)
Output
code will generate long output so run the code for the output :)
0 Comments
Post a Comment