Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do I solve this problem? 1 #In the code below, we've created two dates. The day in each 2 #date is chosen randomly. You

How do I solve this problem?

image text in transcribed

image text in transcribed

image text in transcribed

1 #In the code below, we've created two dates. The day in each 2 #date is chosen randomly. You don't need to worry about how 3 #this works; all you need to know is that when you start 4 writing your code, you'll have access to two variables, each 5 holding a date: earlier_date and later date, and later date 6 is guaranteed to be later than earlier date. 8 Complete this code so that it creates a variable called 9 days between that stores the number of days between the two 12 Hint: You can find the number of days between dodatesli by 13 #subtracting the day number of the earlier de ce from the 14 #day number of the later date. 15 16 from datetime import date 17 import random 18 earlier date = date(2017, 6, random.randint(1, 25)) 19 later date = date (2017, 6, random.randint(earlier_date.day + 1, 28)) 20 21 #Do not modify the code above! 22 23 24 #Write your code here! 25 26 days between = later date earlier date = 9 #days between that stores the number of days between the two 10 #dates. 11 # 12 #Hint: You can find the number of days between two dates by 13 #subtracting the day number of the earlier date from the 14 #day number of the later date. 15 16 from datetime import date 17 import random 18 earlier date date 2017, 6, random.randint(1, 25)) 19 later date date ( 2017, 6, random.randint(earlier_date.day + 1, 28)) 20 21 Do not modry the code above! 22 23 24 write your code 26 days_between later date earlier_date 27 28 #If your code is working correctly then the following line 29 #of code will print the correct number of dayes between the 30 #tivo dates. Notice that this ane uses commas instead of plus 31 #signs, which is why it doesnt have to convert the dates to 32 #strings: Python does that implicitly when we use this syntax, 33 print("There are", days_between, "days between", earlier_date, "and", later_date) 28 #If your code 15 VT18 29 #of code will print the correct number of dayes between the 30 #two dates. Notice that this line uses commas instead of plus 31 #signs, which is why it doesn't have to convert the dates to 32 #strings: Python does that implicitly when we use this syntax. 33 print("There are", days_between, "days between", earlier_date, "and", later_date) [Executed at: Sun Jan 9 0:36:22 PST 2022] We tested your code with earlier_date - 2017-06-15 and later_date - 2017-06-18: We found one thing wrong with your code: We expected the value of the variable days_between to be the int 3, but instead it was the timedelta 3 days, 2:00:00

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions