Advertisement
kecer

matice

Dec 21st, 2013
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. from math import *
  2. class Matica:
  3.         def __init__(self,rows=False,cols=False,n=True):
  4.                 self.r=rows
  5.                 self.c=cols
  6.                 self.val = []
  7.                 if n and rows and cols:
  8.                         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(
  14.                                 x.split(" | ") if " | " in x else x.split(" ")
  15.                         )
  16.  
  17.         def show(self):
  18.                 for i in self.val:
  19.                         print(" ".join(i))
  20.  
  21. class Calc:
  22.         def sum(self,a,b):
  23.                 o=Matica()
  24.                 for I,i in enumerate(b.val):
  25.                         o.val.append([])
  26.                         for Y,y in enumerate(i):
  27.                                 o.val[I].append(str(eval(a.val[I][Y])+eval(y)))
  28.                 o.show()
  29.                 return o
  30.         def mul(self,a,b):
  31.                 o=Matica()
  32.                 for I,i in enumerate(a.val):
  33.                         o.val.append([])
  34.                         for y in range(b.c):
  35.                                 o.val[I].append(str(
  36.                                         sum([eval(i[z])*eval(b.val[z][y]) for z in range(b.r)])
  37.                                 ))
  38.                 o.show()
  39.                 return o
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement