Question: Exercise 6: Program exercise for 2D List Write a complete Python program including minimal comments (file name, your name, and problem description) that solves the

Exercise 6: Program exercise for 2D List

Write a complete Python program including minimal comments (file name, your name, and problem description) that solves the following problem with the main function:

Problem Specification:

The following code reads values from the file object infile and stores them in the 2d list table2: (It assumes that each line contains values of elements in each row and the values are whitespace separated.)

 table2 = [] for line in infile: row=line.split() intRow = [] for ele in row: intRow.append(int(ele)) table2.append(intRow) 

Write a program that finds how many elements the list (table2) are greater than a value provided by a user.

Read a file name and open for reading

Read the contents in the file and store them in a 2D list using the code above.

Ask the user to enter an integer value. Count and print the number of elements that are greater than the value provided by the user.

Repeat the above process until user enters 0 or nothing.

Create the following data file as shown below and test your program.

Make sure you have a main function and there should not be any global variable or statement other than the main function that is being called.

 Sample RUN #1: Enter file name: list2d.txt File list2d.txt converted to 2D list: [31, 33, 35, 37, 39] [1, 3, 5, 7, 9] [11, 13, 15, 17, 19] [21, 23, 25, 27, 29] Enter an integer or 0 for quit: 11 there are 14 elements larger than 11 Enter an integer or 0 for quit: 23 there are 8 elements larger than 23 Enter an integer or 0 for quit: 45 there are 0 elements larger than 45 Enter an integer or 0 for quit: 3 there are 18 elements larger than 3 Enter an integer or 0 for quit: 0 
  Sample input:  31 33 35 37 39 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!