Calendar module in python:-
This module is basically used to provide date and time operations in Python Program.
Calendar module provide date range functionality in python.
This module is used to contain predefined functionality in the Python program, Python is so rich for predefined functionality. all predefine functionality has been defined under the module.
Example of Calendar Module in Python:-
import calendar
print(calendar.month(2014,3))
print(calendar.firstweekday())
if (calendar.isleap(2020)):
print ("The year is leap year")
else :
print ("The year is not leap year")
print (calendar.leapdays(1950, 2000))
print ("The calender of year 2018 is : ")
print (calendar.calendar(2018, 2, 1, 6)) # Y, W, no. of lines per week , No Of columns
ASSIGNMENT using Calendar?
1) WAP to calculate total age in year, month, and a day where the date of birth will be entered by the user?
2) WAP to display before the day, after day when the user enters a number of days.
3) WAP to create STOP watch when pressings s then start, p then pause and e then end?
ABHISHEK GOYAL
ReplyDeleteWAP to calculate total age in year, month, and a day where the date of birth will be entered by the user?
from datetime import date
print("##### Welcome to age calculator ######")
birth_year = int(input("Enter your year of birth: \n"))
birth_month = int(input("Enter your month of birth: \n"))
birth_day = int(input("Enter your day of birth: \n"))
current_year = date.today().year
current_month = date.today().month
current_day = date.today().day
age_year = current_year - birth_year
age_month = abs(current_month-birth_month)
age_day = abs(current_day-birth_day)
print("Your exact age is: ", age_year, "Years", age_month, "months and", age_day, "days")
use this program to correct ouput
Deletefrom datetime import date
a = date(2021, 1, 5)
b = date(1996, 12, 13)
#print(type(a))
months = a.month - b.month
years = a.year - b.year
days = a.day - b.day
print('{0} years, {1} months, {2} days'.format(years, months, days))
import calendar
ReplyDeletefrom datetime import date
year = int(input("Enter your birth year = "))
month = int(input("Enter your birth month in numeric form = "))
day = int(input("Enter your birth date = "))
cy = (date.today().year)
cm = (date.today().month)
cd = (date.today().day)
y = cy-year
m = cm-month
d = cd-day
if d<0 or m<0:
y =y-1
m =m+12
d = d+30
print("You are ",y,"years ",m,"months ",d,"days old")
Post a Comment
If you have any doubt in programming or join online classes then you can contact us by comment .