widgy

Matrix Calulator

Sep 20th, 2021
1,181
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import keyboard
  2. print("Matrix Calculator. ver 1.0")
  3. print()
  4. while True:
  5.     print("What the type of matrix? Second, third or fourth order? [2/3/4]")
  6.     type = [2,3.4]
  7.     a = input()
  8.     for type in a:
  9.         if type == "2":
  10.             print("This matrix has the following form:")
  11.             print()
  12.             print("|A|=|a11 a12|")
  13.             print("    |a21 a22|")
  14.             print()
  15.             print("Enter the required matrix numbers")
  16.             a11 = input("a11: ")
  17.             a12 = input("a12: ")
  18.             a21 = input("a21: ")
  19.             a22 = input("a22: ")
  20.             result = int(a11) * int(a22) - int(a12) * int(a21)
  21.             print("Result:", result)
  22.             break
  23.         if a == "3":
  24.             print("This matrix has the following form:")
  25.             print()
  26.             print("    |a11 a12 a13|")
  27.             print("|A|=|a21 a22 a23|")
  28.             print("    |a31 a32 a33|")
  29.             print()
  30.             print("Enter the required matrix numbers")
  31.             a11 = input("a11: ")
  32.             a12 = input("a12: ")
  33.             a13 = input("a13: ")
  34.             a21 = input("a21: ")
  35.             a22 = input("a22: ")
  36.             a23 = input("a23: ")
  37.             a31 = input("a31: ")
  38.             a32 = input("a32: ")
  39.             a33 = input("a33: ")
  40.             plus = int(a11) * int(a22) * int(a33) + int(a21) * int(a32) * int(a13) + int(a12) * int(a23) * int(a31)
  41.             minus = int(a13) * int(a22) * int(a31) + int(a21) * int(a12) * int(a33) + int(a32) * int(a23) * int(a11)
  42.             result = plus - minus
  43.             print("Result:", result)
  44.             break
  45.         if a == "4":
  46.             print("This matrix has the following form:")
  47.             print()
  48.             print("    |a11 a12 a13 a14|")
  49.             print("|A|=|a21 a22 a23 a24|")
  50.             print("    |a31 a32 a33 a34|")
  51.             print("    |a41 a42 a43 a44|")
  52.             print()
  53.             print("Enter the required matrix numbers")
  54.             a11 = int(input("a11: "))
  55.             a12 = int(input("a12: "))
  56.             a13 = int(input("a13: "))
  57.             a14 = int(input("a14: "))
  58.             a21 = int(input("a21: "))
  59.             a22 = int(input("a22: "))
  60.             a23 = int(input("a23: "))
  61.             a24 = int(input("a24: "))
  62.             a31 = int(input("a31: "))
  63.             a32 = int(input("a32: "))
  64.             a33 = int(input("a33: "))
  65.             a34 = int(input("a34: "))
  66.             a41 = int(input("a41: "))
  67.             a42 = int(input("a42: "))
  68.             a43 = int(input("a43: "))
  69.             a44 = int(input("a44: "))
  70.             print("Form of this matrix:")
  71.             print()
  72.             print("|A|=|",a11, a12, a13, a14,"|")
  73.             print("    |",a21, a22, a23, a24,"|")
  74.             print("    |",a31, a32, a33, a34,"|")
  75.             print("    |",a41, a42, a43, a44,"|")
  76.             print()
  77.             answer = input("Continue? [y/n] ")
  78.             if answer == "y":
  79.                 print("Form of this expression:")
  80.                 print(a11,"|=|",a22, a23, a24,"|-",a12,"|=|",a21, a23, a24,"|+",a13,"|=|",a21, a22, a24,"|-",a14,"|",a21, a22, a23,"|")
  81.                 print(a11,"|=|",a32, a33, a34,"|-",a12,"|=|",a31, a33, a34,"|+",a13,"|=|",a31, a32, a34,"|-",a14,"|",a31, a32, a33,"|")
  82.                 print(a11,"|=|",a42, a43, a44,"|-",a12,"|=|",a41, a43, a44,"|+",a13,"|=|",a41, a42, a44,"|-",a14,"|",a41, a42, a43,"|")
  83.                 result1 = int(a22) * int(a33) * int(a44) + int(a32) * int(a43) * int(a24) + int(a23) * int(a34) * int(a42) - int(a24) * int(a33) * int(a42) - int(a23) * int(a32) * int(a44) - int(a43) * int(a34) * int(a22)
  84.                 result2 = int(a21) * int(a33) * int(a44) + int(a41) * int(a23) * int(a34) + int(a31) * int(a43) * int(a24) - int(a24) * int(a33) * int(a41) - int(a34) * int(a43) * int(a21) - int(a31) * int(a23) * int(a44)
  85.                 result3 = int(a21) * int(a32) * int(a44) + int(a31) * int(a42) * int(a24) + int(a22) * int(a34) * int(a41) - int(a24) * int(a32) * int(a41) - int(a34) * int(a42) * int(a21) - int(a31) * int(a22) * int(a44)
  86.                 result4 = int(a21) * int(a32) * int(a43) + int(a31) * int(a42) * int(a23) + int(a22) * int(a33) * int(a41) - int(a23) * int(a32) * int(a41) - int(a33) * int(a42) * int(a21) - int(a31) * int(a22) * int(a43)
  87.                 print("Result 1:",result1)
  88.                 print("Result 2:",result2)
  89.                 print("Result 3:",result3)
  90.                 print("Result 4:",result4)
  91.                 result = int(a11) * int(result1) - int(a12) * int(result2) + int(a13) * int(result3) - int(a14) * int(result4)
  92.                 print("Final result:", result)
  93.                 break
  94.             if answer == "n":
  95.                 break
  96.     key = input("Process ended. Do you want to take different actions with numbers? [y/n] ")
  97.     if key == "n":
  98.         break
  99.     if key == "y":
  100.         print()
  101.     else:
  102.         print("Incorrect input")
  103.         break
  104. input("Press Enter to exit . . . ")
RAW Paste Data