Home > other >  Help to have a look at these two problems
Help to have a look at these two problems

Time:09-17

CodePudding user response:

 n=3 
Nn=[]
For _ in range (n) :
L=list (map (int, input (" & gt;" ). Strip (). The split (" ")))
Nn. Append (l)

Row=[list (map (lambda x: pow (x, 2), I)) for I nn in]
Col=[[j [I] for j in a row] for I in range (len (row)))
L=list (map (lambda x: sum (row [x]) - the sum (col [x]), the range (n)))
Print (l)


 def proSpace (c) : 
X=c
While "" in x:
X=x.r eplace (" ", "")
Return the x


Def proL (tmpL) :
TmpSum=[tmpL [I] [I] + tmpL [I] is [3 -] I for I in range (len (tmpL)]
Return the sum (tmpSum)


L=[]
While len (l) & lt; 16:
R=proSpace (input (" & gt;" ). Strip ())
L.e xtend (map (int, r.s plit (" ")))

[I * 4 + lr=[[l j] for j in range (4)] for I in range (4)]
Rr=proL (lr)
Print (rr)

CodePudding user response:

Number 6 (writing a bit long-winded )
 def row_and_col_squared_value (two_d_list) : 
"" "[[1, 2, 3], [4, 6], [7,8,9]] "" "
Row_squared=[]
Col_squared=[]
Extend_squared=[]
Row_len=0
For the row in two_d_list:
Row_len=len (row)
TMP=list (map (lambda x: pow (x, 2), the row))
Row_squared. Append (sum (TMP))
Extend_squared. The extend (TMP)
For I in range (0, row_len) :
Total=0
For j in range (0, row_len) :
Total +=extend_squared row_len] [I + j *
Col_squared. Append (total)
Return row_squared, col_squared
Input_num_list=list (map (int, input (' input num: '). The split ()))
Row_len=int (pow (len (input_num_list), 1/2))
Two_d_list=[[input_num_list [j] for j in range (I * row_len, (I + 1) * row_len)] for I in range (row_len)]
Row_squared, col_squared=row_and_col_squared_value (two_d_list)
For the item in the list (map (lambda x, y, x - y, row_squared, col_squared)) :
Print (item, end="")

CodePudding user response:

5 (long-winded is )
 def sum_of_diagonals (two_d_list) : 
"" "[,3,2,4 [1], [8,7,5,6], [15,13,12,11], [9, 8, 10, 6]] "" "
Main_diag=[]
Vice_diag=[]
For I in range (len (two_d_list) :
For j in range (len (two_d_list) :
If j==I:
Main_diag. Append (two_d_list [I] [j])
If j + I==len (two_d_list) - 1:
Vice_diag. Append (two_d_list [I] [j])
Return the sum (main_diag), sum (vice_diag)

Def input_accept_multi_lines (end_ch='/') :
STR='
For the line in iter (input, end_ch) :
STR +=line + '\ n'
Return the STR
Input_num_list=list (map (int, input_accept_multi_lines (). The split () : [16]))
Row_len=int (pow (len (input_num_list), 1/2))
Two_d_list=[[input_num_list [j] for j in range (I * row_len, (I + 1) * row_len)] for I in range (row_len)]
The main and vice=sum_of_diagonals (two_d_list)
Print (main + vice)
  • Related