Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

a. extract_num(s, begin, end) The trickiest part of this problem is this: we have found one or more digits in a string, and we need

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
a. extract_num(s, begin, end) The trickiest part of this problem is this: we have found one or more digits in a string, and we need to extract that number properly or decide to omit it. The extract num() function is decomposed out to focus on that sub-problem. def extract_num(s, begin, end): Given string s, and "begin" is the index of the first of one or more digits, and "end" is the index one beyond the last digit. Parse out and return the int value of the number, accounting for possible 's' and '*'. Return -1 if the number should be skipped. >>> extract_num('xx123$', 2, 5) 321 b. parse_line(s) Given a string, such as a line from a data file, extract all the numbers as described above from the line and return them in order in a list. If the line contains no numbers, return the empty list. One test is provided. Add tests so there are at least five tests. The helper function extract_num( has its own tests, so here you can focus on pulling out a series of numbers. You may find that you need to go back and debug extract num() more if a flaw is exposed at this stage. When you are feeling brave, add a test made from the first example: 8001)1764b006$(46$*#632*16$*06$25* If you have a reverse(s) function from HW4, you can paste it in to this file and use it here as a helper. Later we'll see how to share functions across files, but for now just paste the helper function in. Any helper functions, such as reverse(), should have Pydoc and Doctests. edef extract_nuals, begin, end): Given string s, and "begin" is the index of the first of one or more digits, and "end" is the index one beyond the last digit. Parse out and return the int value of the number, accounting for possible 's' and 'a', Return -1 if the number should be skipped. >>> extract_nun('xx123$, 2, 5) 321 >>> # add Doctests here 29 def. parse line(s): Given a string s, parse the ints out of it and return them as a list of int values. >>> parse_line( '12x76$') [12, 67) >>>> # Add Doctests here pass

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

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions

Question

What is the preferred personality?

Answered: 1 week ago