SimonJkAdamek

Matice

May 16th, 2023
734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. def nacti_matici(rozmer):
  2.     if rozmer < 2:
  3.         print("Rozměr musí být alespoň 2")
  4.         return
  5.  
  6.     matice = [[] for i in range(rozmer)]
  7.     for i in range(rozmer):
  8.         for j in range(rozmer):
  9.             matice[i].append(int(input("Zadej číslo na řádku {} a sloupci {}: ".format(i+1, j+1))))
  10.     return matice
  11.  
  12.  
  13. def soucet(maticeA, maticeB):
  14.     for i in range(len(maticeA)):
  15.         for j in range(len(maticeA)):
  16.             maticeA[i][j]+=maticeB[i][j]
  17.     return maticeA
  18.  
  19. rozmer = int(input("zadej rozměr: "))
  20.  
  21. print("Zadej hodnoty první matice: ", end="\n\n")
  22. matice1 = nacti_matici(rozmer)
  23.  
  24. print()
  25.  
  26. print("Zadej hodnoty druhé matice: ", end="\n\n")
  27. matice2 = nacti_matici(rozmer)
  28.  
  29. matice = soucet(matice1, matice2)
  30.  
  31. print()
  32. for i in range(rozmer):
  33.     for j in range(rozmer):
  34.         print("{0:^5s}".format(str(matice[i][j])), end="")
  35.     print()
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment