Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python 3.4 Human readable dates Below is the code that I have so far but the result is not right. How can I solve the

Python 3.4 Human readable dates image text in transcribed Below is the code that I have so far but the result is not right. How can I solve the problem? def readable_interval(interval): value = interval.split(' ') print(value) intervals = [0, 0, 0, 0, 0, 0] for i in range(len(value)): if i % 2 != 0: if value[i] == 'years' or value[i] == 'year': intervals[0] += int(value[i-1]) elif value[i] == 'month' or value[i] == 'months': intervals[1] += int(value[i-1]) elif value[i] == 'day' or value[i] == 'days': intervals[2] += int(value[i-1]) elif value[i] == 'hour' or value[i] == 'hours': intervals[3] += int(value[i-1]) elif value[i] == 'minute' or value[i] == 'minutes': intervals[4] += int(value[i-1]) elif value[i] == 'second' or value[i] == 'seconds': intervals[5] += int(value[i-1]) return intervals 
Write the function readable-interval that takes a string consisting of a human-readable time interval Homework #3 CSE 101 Spring 2017 Page 3 and converts it into a list of six integers, given in this order: of years, of months, t of days, #of hours, of minutes, of seconds] The input values stored within the string can be quite scrambled and consist of multiple, repeated time components (days, months, etc.), as shown in the examples below. If a time component appears more than once, the values are be added. The time units might be given in singular or plural form (e.g., "month" and "months" are both valid). There will always be at least (but not necessarily exactly) one space between the tokens (i.e., components) of the string. Examples: Function Call: readable-interval 1 year 2 months 3 seconds') Return Value: 1, 2, 0, 0, 0, 31 Function Call: readable-interval 1 second 2 years 3 seconds 7 months 6 days' Return Value: [2, 7, 6, 0, 0, 4 Function Call 4 hours 17 minutes') readable interval 1 days 4 days 3 years Return Value: 13, 0, 5, 4, 17, 01 Function Call readable interval 6 hours 20 minutes 421 seconds Return Value: [0, 0, 0, 6, 20 421] Function Call readable interval 0 days 0 months 7 months 18 years') Return Value: 18 7, 0, 0, 0, 01

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_2

Step: 3

blur-text-image_3

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

DB2 11 The Database For Big Data And Analytics

Authors: Cristian Molaro, Surekha Parekh, Terry Purcell, Julian Stuhler

1st Edition

1583473858, 978-1583473856

More Books

Students also viewed these Databases questions

Question

The TSA mandate includes security measures for:

Answered: 1 week ago

Question

LO14.2 Discuss how game theory relates to oligopoly.

Answered: 1 week ago