Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Rewrite the following code as one single function, create_time_list(filename). def extract time (string): Converts string to time tuple Params string: str Returns tuple containing 3

Rewrite the following code as one single function, create_time_list(filename).

image text in transcribed

def extract time (string): "Converts string to time tuple Params string: str Returns tuple containing 3 member (hours, minues, am/pm) TT TT TT 1s = string.strip().split() # raise error if string is not in proper format if len(13) != 3 or (not ls[0].isnumeric()) or (not ls[1].isnumeric()) or (ls [2] != 'AM' and ls [2] != 'PM'): raise ImproperTimeError("Time is not in proper format.") time = (int(ls[0]), int(1s[1]), 1s[2]) # raise error if value of hour and minute are not in range if time[0] 12 or time[1] 59: raise ImproperTimeError("Time is not is proper format.") return time def create_time_list(filename) : "Reads file for time and converts each line to time tuple Params ---- filename: string name of the file to be processed Returns list of tuples TTTTTT with open(filename, 'r') as file: lines = file.readlines () # raise error if file is empty if len (lines)

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

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions