Advertisement
kecer

matice

Dec 21st, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. from math import *
  2. class Matica:
  3.         def __init__(self,rows=False,cols=False,n=True):
  4.                 self.show = lambda: [print(" ".join(i)) for i in self.val]
  5.                 self.r=rows
  6.                 self.c=cols
  7.                 self.val = []
  8.                 if n and rows and cols: self.insert()
  9.  
  10.         def insert(self):
  11.                 for i in range(self.r):
  12.                         x=input("{0}. riadok: ".format(i+1))
  13.                         self.val.append(x.split(" | ") if " | " in x else x.split(" "))
  14.  
  15. class Calc:
  16.         def sum(self,a,b):
  17.                 o=Matica()
  18.                 for I,i in enumerate(b.val):
  19.                         o.val.append([str(eval(a.val[I][Y])+eval(y)) for Y,y in enumerate(i)])
  20.                 o.show()
  21.                 return o
  22.         def mul(self,a,b):
  23.                 o=Matica()
  24.                 for I,i in enumerate(a.val):
  25.                         o.val.append([])
  26.                         for y in range(b.c):
  27.                                 o.val[I].append(str(sum([eval(i[z])*eval(b.val[z][y]) for z in range(b.r)])))
  28.                 o.show()
  29.                 return o
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement