Python ima vgrajeno funkcijo koledar za delo z opravili, povezanimi z datumom. V tem primeru se boste naučili prikazovati koledar določenega datuma.
Če želite razumeti ta primer, morate poznati naslednje programske teme Python:
- Python moduli
- Python Programiranje vgrajenih funkcij
V spodnji program uvozimo calendar
modul. Vgrajena funkcija month()
znotraj modula upošteva leto in mesec ter prikaže koledar za tisti mesec v letu.
Izvorna koda
# Program to display calendar of the given month and year # importing calendar module import calendar yy = 2014 # year mm = 11 # month # To take month and year input from the user # yy = int(input("Enter year: ")) # mm = int(input("Enter month: ")) # display the calendar print(calendar.month(yy, mm))
Izhod
November 2014 ponedeljek čet petek ne 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
Spremenite lahko vrednost spremenljivk yy in mm in jo zaženete, da preizkusite ta program za druge datume.