Question
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.
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 namesStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started