有没有办法使if条件忽略脚本中的某些行?

2024-09-29 21:42:23 发布

您现在位置:Python中文网/ 问答频道 /正文

有没有办法使if条件忽略某些代码行?这是我的脚本的一部分,它计算了有关矩阵的各种事情:

choice=raw_input("What do you wish to do?(sum/sub/mult/scal/det/trace/transp/cofac/adjointa/inv)")


o =raw_input("Enter dimensions of matrix 1(Ej.:3x4, where 3 is the number of rows and for the number of columns)" " ")
r=raw_input("Enter dimensions of matrix 2" " ")
X=[i for i in o]
Y=[i for i in r]
n,m,p,q=int(X[0]),int(X[2]),int(Y[0]),int(Y[2])

rowsofmatrix1,rowsofmatrix2= {},{}

for i in range (1,n+1):
    while True:
        a=raw_input("Enter row " " " +str(i)+ " " " of the first matrix with each row separated with a space" " ")
        M=split(a)
        if len(M)!=m:
            print "should enter a file of" " "+str(m)+" " "numbers"
            continue
        else:
            break
    M=[float(x) for x in M]
    indexcorrection={}

    for h in range(1,m+1):
        indexcorrection[h]=M[h-1]
    rowsofmatrix1[i]=indexcorrection

for j in range (1,p+1):
    while True:
        b=raw_input("Enter row " " " +str(j)+ " " "of the second matrix with each row separated with a space" " ")
        Q=split(b)
        if len(Q)!=q:
            print "should enter a row with" " "+str(q)+" " "numbers"
            continue
        else:
            break
    Q=[float(x) for x in Q]
    indexcorrection={}
    for h in range(1,q+1):
        indexcorrection[h]=Q[h-1]
    rowsofmatrix2[j]=indexcorrection

所以,你可能知道,行列式是一个矩阵的函数,就像轨迹或逆矩阵一样。在变换中,矩阵的加、减、乘是两个矩阵的函数。所以,我不希望在用户询问第二个矩阵的条目时,比如行列式。另外,我不想问第二个矩阵的维数。 我的问题是:我能做一个假设陈述吗

if choice!=='sum' and choice!=='mult' and choice!='sub': 
     Ignore the whole block which asks for rows of the second matrix. 
     Ignore line which asks dimension of the second matrix
     Ignore the lines which split dimensions of the second matrix

Tags: oftheinforinputrawifwith

热门问题