Skip to content

Commit 8a96143

Browse files
Merge pull request steam-bell-92#1361 from Kirtan-pc/fix/matrix-calculator-dimensions
fix: enforce minimum matrix dimension of 1 in Matrix Calculator
2 parents 8deba8f + 1522ba8 commit 8a96143

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

math/Matrix-Calculator/Matrix-Calculator.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ def main() -> None:
162162

163163
elif choice in ["A", "S"]:
164164
try:
165-
rows = get_int(prompt="➡️ Enter number of rows: ")
166-
cols = get_int(prompt="➡️ Enter number of columns: ")
165+
rows = get_int(prompt="➡️ Enter number of rows: ", min_value=1)
166+
cols = get_int(prompt="➡️ Enter number of columns: ", min_value=1)
167167

168168
print(f"\n📝 Enter elements for Matrix 1 ({rows}x{cols}) row by row (space separated):")
169169
matrix1 = get_matrix_input(rows, cols)
@@ -185,14 +185,14 @@ def main() -> None:
185185

186186
elif choice == "M":
187187
try:
188-
r1 = get_int(prompt="➡️ Enter number of rows for Matrix 1: ")
189-
c1 = get_int(prompt="➡️ Enter number of columns for Matrix 1: ")
188+
r1 = get_int(prompt="➡️ Enter number of rows for Matrix 1: ", min_value=1)
189+
c1 = get_int(prompt="➡️ Enter number of columns for Matrix 1: ", min_value=1)
190190

191191
print(f"\n📝 Enter elements for Matrix 1 ({r1}x{c1}) row by row (space separated):")
192192
matrix1 = get_matrix_input(r1, c1)
193193

194-
r2 = get_int(prompt=f"\n➡️ Enter number of rows for Matrix 2 (MUST be {c1}): ")
195-
c2 = get_int(prompt="➡️ Enter number of columns for Matrix 2: ")
194+
r2 = get_int(prompt=f"\n➡️ Enter number of rows for Matrix 2 (MUST be {c1}): ", min_value=1)
195+
c2 = get_int(prompt="➡️ Enter number of columns for Matrix 2: ", min_value=1)
196196

197197
if c1 != r2:
198198
print("❌ Error: Matrix 1 columns must equal Matrix 2 rows for multiplication.\n")
@@ -212,8 +212,8 @@ def main() -> None:
212212

213213
elif choice == "T":
214214
try:
215-
r = get_int(prompt="➡️ Enter number of rows: ")
216-
c = get_int(prompt="➡️ Enter number of columns: ")
215+
r = get_int(prompt="➡️ Enter number of rows: ", min_value=1)
216+
c = get_int(prompt="➡️ Enter number of columns: ", min_value=1)
217217

218218
print(f"\n📝 Enter elements for Matrix ({r}x{c}) row by row (space separated):")
219219
matrix = get_matrix_input(r, c)
@@ -228,7 +228,7 @@ def main() -> None:
228228

229229
elif choice == "D":
230230
try:
231-
n = get_int(prompt="➡️ Enter size of square matrix (n x n): ")
231+
n = get_int(prompt="➡️ Enter size of square matrix (n x n): ", min_value=1)
232232

233233
print(f"\n📝 Enter elements for Matrix ({n}x{n}) row by row (space separated):")
234234
matrix = get_matrix_input(n, n)
@@ -241,8 +241,8 @@ def main() -> None:
241241

242242
elif choice == "R":
243243
try:
244-
r = get_int(prompt="➡️ Enter number of rows: ")
245-
c = get_int(prompt="➡️ Enter number of columns: ")
244+
r = get_int(prompt="➡️ Enter number of rows: ", min_value=1)
245+
c = get_int(prompt="➡️ Enter number of columns: ", min_value=1)
246246

247247
print(f"\n📝 Enter elements for Matrix ({r}x{c}) row by row (space separated):")
248248
matrix = get_matrix_input(r, c)
@@ -255,7 +255,7 @@ def main() -> None:
255255

256256
elif choice == "I":
257257
try:
258-
n = get_int(prompt="➡️ Enter size of square matrix (n x n): ")
258+
n = get_int(prompt="➡️ Enter size of square matrix (n x n): ", min_value=1)
259259

260260
print(f"\n📝 Enter elements for Matrix ({n}x{n}) row by row (space separated):")
261261
matrix = get_matrix_input(n, n)

0 commit comments

Comments
 (0)