Last active
June 16, 2021 17:30
-
-
Save ialexpovad/781720f26ad997aa37052af7ace18f06 to your computer and use it in GitHub Desktop.
The function return result additional two value (matricies, number, string)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sum(A,B): | |
''' | |
The function return result | |
additional two matrices. | |
parametr A: First variable m x n | |
parametr B: Second variable k x p | |
... | |
return C: result additional | |
''' | |
# Ensure dimensions are valid for matrix additional | |
if type(A)==int and type(B)==int or type(A)==str and \ | |
type(B)==str or type(A)==float and type(B)==float: | |
return A+B | |
else: | |
m,n,k,p=len(A),len(A[0]),len(B),len(B[0]) | |
if m!=k or n!=p: | |
raise ArithmeticError('Not the same size.') | |
# Initial zeros matrix | |
C=[[0]*n for _ in range(n)] | |
# Perform element by element sum | |
for i in range(m): | |
for j in range(n): | |
C[i][j]=A[i][j]+B[i][j] | |
return C | |
if __name__=='__main__': | |
A='Жыве ' | |
B='Беларусь!' | |
print(sum(A,B)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment