Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am getting the following error The call sunset(datetime.date(2014, 6, 2),daycycle) crashed. Traceback (most recent call last): File /home/codio/workspace/.guides/tests/problem4/verifier.py, line 385, in grade_func2 received =

I am getting the following error

The call sunset(datetime.date(2014, 6, 2),daycycle) crashed. Traceback (most recent call last): File "/home/codio/workspace/.guides/tests/problem4/verifier.py", line 385, in grade_func2 received = func(data[0],daycycle) File "/home/codio/workspace/exercise4/funcs.py", line 81, in sunset return datetime.datetime.strptime(sunset_date_time, "%Y-%m-%d %H:%M") TypeError: strptime() argument 1 must be str, not None

Below is my code and I am unsure how to fix it I think the issue is coming from the return statement

def sunset(date,daycycle): """ Returns the sunset datetime (day and time) for the given date This function looks up the sunset from the given daycycle dictionary. If the daycycle dictionary is missing the necessary information, this function returns the value None. A daycycle dictionary has keys for several years (as int). The value for each year is also a dictionary, taking strings of the form 'mm-dd'. The value for that key is a THIRD dictionary, with two keys "sunrise" and "sunset". The value for each of those two keys is a string in 24-hour time format. For example, here is what part of a daycycle dictionary might look like: "2015": { "01-01": { "sunrise": "07:35", "sunset": "16:44" }, "01-02": { "sunrise": "07:36", "sunset": "16:45" }, ... } Parameter date: The date to check Precondition: date is a date object Parameter daycycle: The daycycle dictionary Precondition: daycycle is a valid daycycle dictionary, as described above """ # HINT: ISO FORMAT IS 'yyyy-mm-ddThh:mm'. For the sunrise value, construct a # string in ISO format and call str_to_time. sunset_date_time = None year = date.strftime("%Y") year_data = daycycle.get(year)

if(year_data != None): month_day = date.strftime("%m-%d")

result_set = year_data.get(month_day) if(result_set != None): sunset_time = result_set["sunset"] sunset_date_time = year + "-" + month_day + " " + sunset_time return datetime.datetime.strptime(sunset_date_time, "%Y-%m-%d %H:%M")

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

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions