Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def fill(rz, ko, fill=0):
- tab=[]
- temp = []
- for i in range(ko):
- temp.append(fill)
- for i in range(rz):
- tab.append(temp)
- return tab
- def podaj(rz, ko):
- tab=[]
- for i in range(rz):
- temp=list(map(float, input().split()))
- while len(temp)!=ko:
- temp=list(map(float, input("Błędna ilość liczb").split()))
- tab.append(temp)
- return tab
- class matrix:
- def __init__(self, rzedy, kolumny, wartosci=None):
- self.rzedy = rzedy
- self.kolumny = kolumny
- if wartosci==None:
- self.wartosci=fill(rzedy, kolumny)
- else:
- self.wartosci = wartosci
- def __str__(self):
- temp=str()
- for i in self.wartosci:
- for j in i:
- temp=temp+str(j)+" "
- temp=temp + "\n"
- return temp
- def __add__(self1, self2):
- try:
- temp = matrix(self1.rzedy, self1.kolumny)
- for i in range(self1.rzedy):
- for j in range(self1.kolumny):
- temp.wartosci[i][j]=self1.wartosci[i][j]+self2.wartosci[i][j]
- return temp
- except:
- return "macierze nie mogą być dodane"
- wier=int(input("Wiersze:"))
- kol=int(input("Kolumny:"))
- mac1=matrix(wier, kol, podaj(wier, kol))
- wier=int(input("Wiersze:"))
- kol=int(input("Kolumny:"))
- mac2=matrix(wier, kol, podaj(wier, kol))
- print(mac1+mac2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement