Please use all the steps that are given

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Please use all the steps that are given 

Write a python program to determine if two dates are within 30 days of each other. We shall define being within 30 days
as from and including the start date and up to but not including the end date. For instance, 4/15 - 5/15 and 12/1 -
12/31 are both within 30 days of each other.
Assume: dates are given within the same year but not necessarily in a specific order. Meaning, both the pair 4/15, 5/15
and 5/15, 4/15 are both considered within 30 days of each other. The months are given as [1-12] and the days [1-
31].
Your solution must implement the algorithm below for credit.
Use the following algorithm to implement your solution:
• Define a function dayInYear
This function requires two parameters: a month and a day.
The function should return an integer between 1 and 365.
Create a list, daysInMonth, with values: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31].
o Use the three data points, month, day , and daysInMonths to convert a month/day pair into a days in year value.
For instance, 4/21 is 31 + 28 + 31 + 21 = 111.
Hint: what is the relationship between the month and indexes in the list daysInMonths ?
Define a function withinThirtyDays
This function requires four parameters: first month, first day, second month, second day. This is the input. The
function should return True or False.
Convert the first month/first day pair into the day in year format using the dayInYear function. For instance, 4/21
is the 111 day in the year.
Convert the second month/second day pair into the day in year format using the dayInYear function.
Take the absolute value of the difference between the two.
If it is less than or equal to 30, return True. Otherwise, return False.
For testing, you can use these asserts:
assert( withinThirtyDays (4,15, 5,15) == True)
= True)
assert( withinThirtyDays(5,15, 4,15) == True)
assert( withinThirtyDays (1,31, 3,1) == True)
True)
assert( withinThirtyDays (3,1, 1,31)
assert( withinThirtyDays(5,1, 6,1) == False)
assert( withinThirtyDays(6,1, 5,1 ) == False)
assert( withinThirtyDays(2,16, 6,12 ) == False)
assert( withinThirtyDays(1,17, 1,12 ) == True)
assert( withinThirtyDays(12,1, 12,31 ) == True)
Transcribed Image Text:Write a python program to determine if two dates are within 30 days of each other. We shall define being within 30 days as from and including the start date and up to but not including the end date. For instance, 4/15 - 5/15 and 12/1 - 12/31 are both within 30 days of each other. Assume: dates are given within the same year but not necessarily in a specific order. Meaning, both the pair 4/15, 5/15 and 5/15, 4/15 are both considered within 30 days of each other. The months are given as [1-12] and the days [1- 31]. Your solution must implement the algorithm below for credit. Use the following algorithm to implement your solution: • Define a function dayInYear This function requires two parameters: a month and a day. The function should return an integer between 1 and 365. Create a list, daysInMonth, with values: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]. o Use the three data points, month, day , and daysInMonths to convert a month/day pair into a days in year value. For instance, 4/21 is 31 + 28 + 31 + 21 = 111. Hint: what is the relationship between the month and indexes in the list daysInMonths ? Define a function withinThirtyDays This function requires four parameters: first month, first day, second month, second day. This is the input. The function should return True or False. Convert the first month/first day pair into the day in year format using the dayInYear function. For instance, 4/21 is the 111 day in the year. Convert the second month/second day pair into the day in year format using the dayInYear function. Take the absolute value of the difference between the two. If it is less than or equal to 30, return True. Otherwise, return False. For testing, you can use these asserts: assert( withinThirtyDays (4,15, 5,15) == True) = True) assert( withinThirtyDays(5,15, 4,15) == True) assert( withinThirtyDays (1,31, 3,1) == True) True) assert( withinThirtyDays (3,1, 1,31) assert( withinThirtyDays(5,1, 6,1) == False) assert( withinThirtyDays(6,1, 5,1 ) == False) assert( withinThirtyDays(2,16, 6,12 ) == False) assert( withinThirtyDays(1,17, 1,12 ) == True) assert( withinThirtyDays(12,1, 12,31 ) == True)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY