In: Computer Science
(Python) How would I add this input into my code? "Enter Y for Yes or N for No:" as a loop.
def getMat():
mat = np.zeros((3, 3))
print("Enter your first 3 by 3 matrix:")
for row in range(3):
li = [int(x) for x in input().split()]
mat[row,0] = li[0]
mat[row,1] = li[1]
mat[row,2] = li[2]
print("Your first 3 by 3 matrix is :")
for i in range(3):
for k in range(3):
print(str(int(mat[i][k]))+" ",end="")
print()
return mat
def checkEntry(inputValue):
try:
float(inputValue)
except ValueError:
return False
return True
print('Enter first matrix: ')
mat1 = getMat()
print('Enter second matrix: ')
mat2 = getMat()
print('Select a Matrix Operation from the list below:')
print('a. Addition')
choice = str(input())
while choice != 'e':
if choice == 'a':
print('You selected Addition. The results are: ')
res = mat1 + mat2
import numpy as np
def getMat():
mat = np.zeros((3, 3))
print("Enter your first 3 by 3 matrix:")
for row in range(3):
li = [int(x) for x in input().split()]
mat[row, 0] = li[0]
mat[row, 1] = li[1]
mat[row, 2] = li[2]
print("Your first 3 by 3 matrix is :")
for i in range(3):
for k in range(3):
print(str(int(mat[i][k])) + " ", end="")
print()
return mat
def checkEntry(inputValue):
try:
float(inputValue)
except ValueError:
return False
return True
while True:
print('Enter first matrix: ')
mat1 = getMat()
print('Enter second matrix: ')
mat2 = getMat()
print('Select a Matrix Operation from the list below:')
print('a. Addition')
choice = str(input())
while choice != 'e':
if choice == 'a':
print('You selected Addition. The results are: ')
res = mat1 + mat2
choice = input('Enter Y for Yes or N for No:')
if choice == 'N' or choice == 'n':
break