In this Python challenge, we are going to investigate how to manipulate dates in Python using the datetime library.
The aim of this challenge is to write a piece of code to control the Time Machine (aka Flux Capacitor) found in the De Lorean Time Machine used in the Back to the Future trilogy.
Time Machine (Flux Capacitor) Requirements
The python code used to control the time machine will:
-
Display the current date (today),
Display the day of the week of the current date,
Ask the user to input a number representing the number of days for their time travel:
-
A positive number to time travel in the future.
A negative number to time travel in the past.
Workout the end date by adding the number of days to time travel to the current date,
Display the end date and the day of the week for this end date.
Python Code
Here is the Python code for our time machine!
Your Challenge
Write a Python script to work out the number of days between a specific date and today’s date.
For instance, if you would like to travel to the the Moon Landing Day: 16 Jul 1969. How many days would you need to travel back in time?
Your script will be very useful to configure the De Lorean time machine!
Your script should:
-
Display the current date (today),
- Output the number of days between the two dates.
Display the day of the week of the current date,
Ask the user to enter a date in the DD/MM/YYYY format,
Convert the user entry into a date,
Calculate the difference in days between the current date and today’s date
-
This difference should be a negative number of days of the input date is in the past.
This difference should be a positive number of days of the input date is in the future.
To test if your script is working, you can then input the resulting number of days in the DeLorean Time Machine above script and see if the resulting end date matches your input.
Solution...
The solution for this challenge is available to full members!Find out how to become a member:
➤ Members' Area