Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function extract_num ( ) which takes two parameters: a file-name and an integer ( x ). Your function should do the following: Read

Write a function extract_num( ) which takes two parameters: a file-name and an integer (x). Your function should do the following:

Read the input file -- either line-by-line or entirely at once

Use either: readline() or read()

Create a list (lst1) which contains all words (strings) from the file as its elements.

use split( )

Create a new list (lst2) which contains all integers from lst1 which are greater than x.

use int( ) to convert words that are strings to integers

Find and print the maximum value from lst2

do not use max( )

Return lst2

Note: The input file that will be used to test your function will contain numerous integers randomly spaced, on multiple lines.

To explain this further, assume you have a file that contains the following:

34 23 53 22 454 223 222 33 2 333 4 2 100

lst1 should be ['34', '23', '53', '22', '454', '223', '222', '33', '2', '333', '4', '2', '100']

if x (second parameter) is 100,

lst2 should be [454, 223, 222, 333]

then, print max which is 454

finally return lst2

Code the following using python idle and be sure not to use the constructs in the prohibited list unless specified in the question. Do not use append or built in max() function.

image text in transcribed

You are not allowed to use built-in constructs especially: list, append, max, sort, etc.

You are allowed to use: open( ), close( ), read( ), readline( ), int( ), split( )

directions. Using the following constructs will result in 0 (zero) for the entire submission (assignment, timed test, etc.). The restricted items are as follows: - Concepts not discussed in lectures yet - String functions - Member functions - Exceptions (can use) : /en () and x=x+[y1,y2,y3] - Built-in functions \& types - Exceptions (can use): str( ), readline( ), open(), close( ), write(), read(), range( ), .split() - Cannot use .append, .sort, etc. - Cannot use "Slicing" - Cannot use "list comprehension" - Cannot use "not in" (together) - Cannot use "in" - not allowed with conditionals - Exception (can use): with range () - Cannot use and \{\} - Exception (can use): mathematical operations (multiply \& exponents) - Data type functions - Exceptions (can use): int (), str (), float () - Break - Continue - Nested Constructs - Exceptions (can use): 2-D list - Multiple returns \& Multiple assignments - Recursion (not allowed unless the question explicitly states otherwise) - Functions within functions (Definitions) -- invocation is fine - Default Parameters - Global variables - Keyword as variable names

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

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions

Question

8. Explain competency models and the process used to develop them.

Answered: 1 week ago