Question

In: Computer Science

Write a Python program which adds up columns and rows of given table as shown in...

Write a Python program which adds up columns and rows of given table as shown in the specified figure. Example test case (the four lines below “Input cell value” are input from user, and the five lines below “Results:” are the output of the program.):

Input number of rows/columns (0 to exit)

4

Input cell value:

25 69 51 26

68 35 29 54

54 57 45 63

61 68 47 59

Result:

            25   69   51   26 171

            68   35   29   54 186

            54   57   45   63 219

            61   68   47   59 235

          208 229 172 202 811

Input number of rows/columns (0 to exit)

Solutions

Expert Solution

#Python code

while True:
    N = int(input('Input number of rows/columns (0 to exit): '))
    if N==0:
        break
    arr = [[0 for i in range(N+1)] for j in range(N+1)]
    print('Input cell value:')
    for i in range(N):
        for j in range(N):
            arr[i][j] = int(input())

    for i in range(N) :
        for j in range(N) :
            arr[N][i] += arr[j][i]

    for i in range(N+1) :
        for j in range(N) :
            arr[i][N] += arr[i][j]

    for i in range(N+1) :
        for j in range(N+1) :
            print("%4d"%arr[i][j],end = ' ')
        print()


#Screenshot


Related Solutions

Write a Python program which adds up columns and rows of given table as shown in...
Write a Python program which adds up columns and rows of given table as shown in the specified figure. Example test case (the four lines below “Input cell value” are input from user, and the five lines below “Results:” are the output of the program.): Input number of rows/columns (0 to exit) 4 Input cell value: 25 69 51 26 68 35 29 54 54 57 45 63 61 68 47 59 Result: 25 69 51 26 171 68 35...
"Create a program that displays a table consisting of four rows and five columns. The first...
"Create a program that displays a table consisting of four rows and five columns. The first column should display the numbers 1 through 4. The second and sub-sequent columns should display the result of multiplying the number in the first column by the numbers 2 through 5. If necessary, create a new project named Introductory14 Project, and save it in the Cpp8\Chap08 folder. Enter the C++ instructions into a source file named Introductory14.cpp. Also enter appropriate comments and any additional...
Using the Python program: a/ Write a program that adds all numbers from 1 to 100...
Using the Python program: a/ Write a program that adds all numbers from 1 to 100 to a list (in order). Then remove the multiples of 3 from the list. Print the remaining values. b/ Write a program that initializes a list with ten random integers from 1 to 100. Then remove the multiples of 3 and 5 from the list. Print the remaining values. Please show your work and explain. Thanks
Assume that A and B are MATLAB arrays with 10 rows and an equal number of columns (the number of columns is not given).
Assume that A and B are MATLAB arrays with 10 rows and an equal number of columns (the number of columns is not given). Important: Next, the expression "a single line of code" implies a single command or equality. In other words, the code: X=A+1; X=X+B; is considered to be TWO lines of code, even though it can be written as one line. (a) (3%) Write a single line of code which saves the first two rows of array A...
The Lo Shu Magic Square is a grid with 3 rows and 3 columns shown in...
The Lo Shu Magic Square is a grid with 3 rows and 3 columns shown in Figure 8-23. The Lo Shu Magic Square has the following properties: l The grid contains the numbers 1 through 9 exactly. l The sum of each row, each column, and each diagonal all add up to the same number. This is shown in Figure 8-24. In a program, you can simulate a magic square using a two-dimensional array. Design a program that initializes a...
Write a Python program, in a file called StickFigure.py, which, given a value for the total...
Write a Python program, in a file called StickFigure.py, which, given a value for the total height of a stick figure, uses a recursive function to generate the stick figure pattern as shown below. The recursive function is used to print the entire figure. Note that the head, arms and legs stay the same, but the body can be different lengths, depending on what the user enters as the height of the figure. The "body" length is always 3 lines...
Write a script to display the following patterns on the screen. Number of rows and columns...
Write a script to display the following patterns on the screen. Number of rows and columns are taken from the command arguments; if they are missing, set default to 3 (rows) and 4 (columns). Hint: you will use a nested loop. **** **** **** a) Display the source code in an editor (#4-11) b) Execute your script in the terminal, and display the command and the result (#4-12)
When testing for independence in a contingency table with 2 rows and 2 columns at 5%...
When testing for independence in a contingency table with 2 rows and 2 columns at 5% level of significance, the critical value of the test statistic is____
1 – Create a webpage that contains a table with exactly three rows and two columns....
1 – Create a webpage that contains a table with exactly three rows and two columns. The first row will contain a table heading containing the name of a US National Park, that spans across all columns. Hint: use the colspan attribute inside the opening th tag Give the table heading an onmouseover that will change the text of the heading when it is moused over to read My Favorites Park! (Hint: use innerHTML). Use onmouseout to change it back....
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. A: 90% - 100% B 80% - 89% C 70% - 79% D 60% - 69% F <60% The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT