Question

Python Basic Lists, File IO, Exception Handling 1. Call createTable() to: Read in the data from...

Python Basic

Lists, File IO, Exception Handling

1. Call createTable() to:

Read in the data from each of the input files (in order from scores1.txt to scores5.txt) and store the data in table. The table is a list of lists, where the scores of each input file is a column of data of the table.

By the end of the function, the table should have 5 columns of numbers, each column is from one input file. Here is the first 4 rows of the table:

                                [83, 93, 85, 89, 97]

                                [95, 88, 85, 93, 95]

                                [88, 95, 84, 90, 96]

                                [72, 93, 70, 77, 97] ...

If any file can't be successfully opened, print an error message and end the program

Part 1, of 4

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def createTable():
    data = []
    for i in range(1, 6):
        filename = 'scores' + str(i) + '.txt'
        index = 0
        try:
            with open(filename, 'r') as f:
                for line in f:
                    for word in line.strip().split():
                        if index >= len(data):
                            data.append([])
                        data[index].append(int(word))
                        index += 1
        except:
            print('Failed to open ' + filename)
    print(data)

createTable()
Add a comment
Know the answer?
Add Answer to:
Python Basic Lists, File IO, Exception Handling 1. Call createTable() to: Read in the data from...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please help me with this program.You are to write a C++ program that will read in...

    Please help me with this program.You are to write a C++ program that will read in up to 15 students with student information and grades. Your program will compute an average and print out certain reports. Format: The information for each student is on separate lines of input. The first data will be the student�s ID number, next line is the students name, next the students classification, and the last line are the 10 grades where the last grade is...

  • Pitcher 1 Pitcher 2 87 82 86 92 82 70 84 96 83 89 81 84 85 84 93 ...

    Pitcher 1 Pitcher 2 87 82 86 92 82 70 84 96 83 89 81 84 85 84 93 80 86 81 85 89 84 86 92 72 83 77 84 87 80 89 87 93 88 78 87 81 79 82 82 87 82 81 87 84 80 88 88 93 90 80 85 79 86 87 87 74 86 78 85 80 85 83 88 79 84 95 83 81 88 89 87 91 94 93 83 91...

  • 8. The following data are scores from a Physics final administered to 34 students. 81 76...

    8. The following data are scores from a Physics final administered to 34 students. 81 76 93 99 47 67 69 72 83 88 56 62 91 94 98 63 77 84 98 75 79 67 73 65 89 86 91 85 97 73 56 92 88 83 Use the Chart below to construct a Frequency Distribution with 5 classes (15 pts) Class Tally (This column is optional.) Frequency

  • write a program that uses a function to read in the grades for four classes and...

    write a program that uses a function to read in the grades for four classes and then uses a function to calculate the average grade in each of the classes. input the grades for one student. we will name her Beverly. output how Beverly's grade differs from each classe average. Make sure that your output is very clear. Below is your data: English 90 70 85 45 95 95 82 97 99 65 History 63 94 60 76 83 98...

  • (IN PYTHON) You are to develop a Python program that will read the file Grades-1.txt that...

    (IN PYTHON) You are to develop a Python program that will read the file Grades-1.txt that you have been provided on Canvas. That file has a name and 3 grades on each line. You are to ask the user for the name of the file and how many grades there are per line. In this case, it is 3 but your program should work if the files was changed to have more or fewer grades per line. The name and...

  • use  JOptionPane to display output Can someone please help write a program in Java using loops, not...

    use  JOptionPane to display output Can someone please help write a program in Java using loops, not HashMap Test 1 Grades After the class complete the first exam, I saved all of the grades in a text file called test1.txt. Your job is to do some analysis on the grades for me. Input: There will not be any input for this program. This is called a batch program because there will be no user interaction other than to run the program....

  • C++: Create a grade book program that includes a class of up to 20 students each...

    C++: Create a grade book program that includes a class of up to 20 students each with 5 test grades (4 tests plus a Final). The sample gradebook input file (CSCI1306.txt) is attached. The students’ grades should be kept in an array. Once all students and their test scores are read in, calculate each student’s average (4 tests plus Final counts double) and letter grade for the class. The output of this program is a tabular grade report that is...

  • 'Student Pair' 'Standard Teaching Method' 'New Teaching Method' 1 51 67 2 72 90 3 85...

    'Student Pair' 'Standard Teaching Method' 'New Teaching Method' 1 51 67 2 72 90 3 85 82 4 51 63 5 73 76 6 72 73 7 65 78 8 72 94 9 72 85 10 95 100 11 70 80 12 60 72 13 57 100 14 48 58 15 74 89 16 63 97 17 82 88 18 57 45 19 87 81 20 65 99 21 48 69 22 97 70 23 61 47 24 83 73...

  • 1.         For each set below, using Excel, construct            a.         a frequency distribution,   ...

    1.         For each set below, using Excel, construct            a.         a frequency distribution,    b.         a relative frequency distribution, and            c.         a cumulative relative frequency distribution. Consider whether or not you should group your data. Describe how you determined your bin width, if you grouped the data in intervals. Set 1 75    95    103 100 93 91 90 92 89 105 86 85 81 96 103 99 94 95 91 97 92 107...

  • THIS IS FINAL COURSE ASSIGNMENT, PLEASE FOLLOW ALL REQUIREMENTS. Hello, please help write program in JAVA...

    THIS IS FINAL COURSE ASSIGNMENT, PLEASE FOLLOW ALL REQUIREMENTS. Hello, please help write program in JAVA that reads students’ names followed by their test scores from "data.txt" file. The program should output "out.txt" file where each student’s name is followed by the test scores and the relevant grade, also find and print the highest test score and the name of the students having the highest test score. Student data should be stored in an instance of class variable of type...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT