python - Reading Two Input Files -


i have following problem statement:

write program that:

  1. reads 2 inputs files
  2. populates 2 dimensional table integers contained in each file
  3. check size of 2 tables make sure both have same number of rows , columns. if tables not same size print error message
  4. once have read data each file create third table
  5. the elements in third table result of multiplying each element in first table corresponding element in second table: thirdtable [i] [j] = firsttable[i] [j] * secondtable[i] [j]

i need know how put second file in code far.and how write code table three. here code first input file:

def main():     print("table one")     (row, column, table) = readinput()     return()   def readinput():     table = []     inputfile = open("table 1.txt", "r")       #  read first line containing number of rows , columns     line = inputfile.readline()      #  split line 2 strings     (row, column) = line.split()      #  convert strings integers     row = int(row)     column = int(column)      #  loop on file container, reading each line      line in inputfile :         line = line.rstrip()  #strip off newline          datalist = line.split()  #  split string list          table.append(datalist)   #  loop through table , convert each element integer       in range(row):         j in range (column):             table[i] [j] = int(table[i] [j])  # convert string integer             print(" %3d" % (table[i] [j]), end = " ")         print()      inputfile.close()  #  close file     return(row, column, table)  #  return number of rows , columns   main()     

you can make readinput function take parameter:

def readinput(filename):     #         ^^^^^^^^ change here      table = []     inputfile = open(filename, "r")     #       , here ^^^^^^^^      ... # rest of function 

then use main this:

def main():      row1, column1, table1 = readinput('table1.txt')      row2, column2, table2 = readinput('table2.txt') 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -