1 Replies - 251 Views - Last Post: 13 November 2019 - 02:42 AM Rate Topic: -----

#1 kam536   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 21-March 18

Entry checker

Posted 12 November 2019 - 08:22 PM

import numpy as np

print("Hello,\n")
print("Welcome to the Python Matrix Application")

def menu():
    print("Do you want to play the Matrix Game?: ")
    entry=input("Enter Y for Yes or N for No")
    if entry =="Y":
        print("Please enter your matrixs")
    elif entry =="N":
        print("Thank-you for trying the Python Matrix Game!")
        break
    else:
        print("Invalid entry please restart and try again")
    
def checkEntry(inputValue):
    try:
        float(inputValue)
    except ValueError:
        return False
    return True   
    
def enterMatrixs():
    matrix = np.zero((3,3))
    for row in range(3):
        for column in range(3):
            check=False
            while not check:
                entry=input('Enter element at position ({:D/>/>},{:D/>/>}):'\
                .format(row + 1, column + 1)
                 check= checkEntry(entry)
                if not check:
                    print('Please enter a numeric value!')
            mat[row, column] = float(num)
        print()
    return matrix 

    return matrix


print("Please Enter your first 3x3 matrix:\n")
matrix1=enterMatrixs()
print(matrix1)

print("Please Enter your second 3x3 matrix")
matrix2=enterMatrixs()
print(matrix2)

print("Select a Matrix Operation form the list below:")
print("a.Addition")
print("b.Subtraction")
print("c.Matrix Multiplication")
print("d.Element by Element Multiplication")

selection= input("What is your Selection?: ")


while True:
    selection=menu()
    if selection == 1:
        print("You selected Addition. The results are: ")
        add = matrix1 + matrix2
        print(add)
        print("The Transpose of the results are: ")
        print(add.T)
        print("The row and column mean values of the results are: ")
        print("Rows: ",np.mean(add,1))
        print("Columns: ",np.mean(add,0))
    
    if selection == 2:
        print("You selected Subtraction. The results are: ")
        sub = matrix1 - matrix2
        print(sub)
        print("The Transpose of the results are: ")
        print(sub.T)
        print("The row and column mean values of the results are: ")
        print("Rows: ",np.mean(sub,1))
        print("Columns: ",np.mean(add,0))
        
    if selection == 3:
        print("You selected Matrix Multiplication. The results are: ")
        mul = np.matmul(matrix1,matrix2)
        print(mul)
        print("The Transpose of the results are: ")
        print(mul.T)
        print("The row and column mean values of the results are: ")
        print("Rows: ",np.mean(mul,1))
        print("Columns: ",np.mean(mul,0))
        
        
    if selection == 4:
        print("You selected Element by Element Multiplication.The results are:")
        emul = np.multiply(matrix1,matrix2)
        print(emul)
        print("The Transpose of the results are: ")
        print(emul.T)
        print("The row and column mean values of the results are: ")
        print("Rows: ", np.mean(emul,1))
        print("Columns: ", np.mean(emul,0))
        
        
    else:
        print("Invaild Entry. Restart and try again!")
        
    
    








This is the error I am receiving:
File "/home/ec2-user/environment/Project4/Python Matrix Math Application Code.py", line 38
check = checkEntry(entry)
^
SyntaxError: invalid syntax




How would I make the checkEntry to work correctly?

Is This A Good Question/Topic? 0
  • +

Replies To: Entry checker

#2 ndc85430   User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 981
  • View blog
  • Posts: 3,870
  • Joined: 13-June 14

Re: Entry checker

Posted 13 November 2019 - 02:42 AM

Are you missing the closing paren for input on line 31?

Also, the plural of "matrix" is "matrices".
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1