0% found this document useful (0 votes)
36 views4 pages

Exp19 20

Uploaded by

Rajan Thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
36 views4 pages

Exp19 20

Uploaded by

Rajan Thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4
Experiment 19 & 20 ‘The datetime module provides date and time objects and provides a rich set of methods and operators, Read the documentation at hitps:/idocs. python ora/Silibrary/datetime.html and at nitos:/www.w3schools.com/python/python_datetime.asp 1. Use the datetime module to write a program that gets the current date and prints the day of the week. Program Code: Input-Output: Today is Tuesday 2. Write a program that takes a birthday as input and prints the user's age and the number of days, hours, minutes and seconds until their next birthday. Program Code: eres errs een etared nena reat prereeeeeee es Coes naetes Perea essen (reece) rere ee eee eet) Pere ee ees ess ae an Coreen aces ere aE Ne ESSN CeeNaeet sp) next birthday = datetime (current _date.year + 1. birthday.month, birthday day) Ce eeEtT Smee teas aera react peerererrcy Pa eeurarstie re stcst hy (Cormeremret errors Sern) ocr erent) Corremmnresel oeneree merce Tease a aE oot eeaeet ecmtce eres Seca errno Foe SUMO MRC Cae Sess CoN Era} ROnCe meso Ome ae Cece seas tet ra Cy Sere ) UCM S emt e es Crt c Presses (age, time_until_next birthday) 0 Input-Output: Enter your birthday (YYYY-MM-DD): 2004-08-30 You are 19 years old. Time until your next birthday: 282 days, 14 hours, 22 minutes, 57 seconds. 3. For two people born on different days, there is a day when one is twice as old as the other. That's their DoubleDay. Write a program that takes two birthdays and computes their Double Day. Program Code: Input-Output: Enter the first birthday (YYYY-MM-DD): 2003-08-30 Enter the second birthday (YYYY-MM-DD): 2006-09-12 The Double Day is: 2009-09-25 4, For a little more challenge, write the more general version that computes the day when one person is n times older than the other. Program Code: from datetime import dat: timedelta Input-Output: Enter the first birthday (YYYY-MM-DD): 2003-08-30 Enter the second birthday (YYYY-MM-DD): 2006-08-12 Enter the value of n (e.g., 2 for double, 3 for triple, etc.): 3 ‘The day when one person is 3.0 times older is: 2015-06-20

You might also like