Examples¶
Code Examples
Matrix¶
Multiplying Matrices¶
Create and multiply two matrices¶
from YAPM import Matrix
a = Matrix.Matrix(
[[1, 2, 3],
[4, 2, 4]]
)
b = Matrix.Matrix(
[[9, 1],
[4, 1],
[3, 3]]
)
print((a * b)) # [[26, 12], [56, 18]]
Get Value From Matrix¶
Get value from matrix at 2, 0¶
from YAPM import Matrix
a = Matrix.Matrix(
[[1, 2, 3],
[4, 2, 4]]
)
print(a.GetValue(2, 0) # 3
Terminal¶
Terminal¶
Print funky text¶
from YAPM import Terminal
t = Terminal.Terminal(TrueColor=True) # Indicate we have true color
t.print((0, 255, 0), (23, 60, 162), "Test") # Print "Test" with a blue background and green text
Other Functions¶
RaisesError¶
Try to get value from list and print if errored¶
from YAPM import Other
def is_list(a):
result = Other.RaisesError("a[0]", GlobalVars={"a": a})
if result[0]:
print(f"a[0] is {result[1]}") # Result[1] is the return value
else:
print(f"a[0] threw {result[1]}") # Result[1] is the error.
is_list([0, 1, 2]) # a[0] is 0
is_list(1) # a[0] threw 'int' object is not subscriptable