2013-12-08 6 views
1

파일 목록을 읽는 중 목록에서 인쇄하는 데 문제가 있습니다.목록 및 인쇄 목록이있는 Python 문제

input1,input2,input3 = eval(input()) 
inputList1 = [] 
inputList2 = [] 
inputList3 = [] 
inputListA = [] 
inputListB = [] 
inputListC = [] 
rootList1 = [] 
rootList2 = [] 

print(format('Coefficients','15s'),format('# of Roots','15s'),'Roots') 
print('==================================================') 

while (input1 != 0 and input2 != 0 and input3 != 0): 
    rootProc = QuadEq(input1,input2,input3) 
    rootS = rootProc.discRoot() 
    if (rootS == 0): 
     inputList2.append(input1) 
     inputList2.append(input2) 
     inputList2.append(input3) 
     inputListB.append(inputList2[:]) 
     rootList1.append(rootProc.RootOne()) 
    elif (rootS > 0): 
     inputList3.append(input1) 
     inputList3.append(input2) 
     inputList3.append(input3) 
     inputListC.append(inputList3[:]) 
     rootList2.append(rootProc.RootOne()) 
     rootList2.append(rootProc.RootTwo()) 
    else: 
     inputList1.append(input1) 
     inputList1.append(input2) 
     inputList1.append(input3) 
     inputListA.append(inputList1[:]) 

    input1,input2,input3 = eval(input()) 

for i in range(len(inputListA)): 
    print(format(inputListA,'5s'), format('No Real Roots','>15s'), '') 

이것은 내가하고 싶은 부분의 부분 만 인쇄합니다. 그러나 나는 시험을하고 있습니다. 제가

1 1 1 No Real Roots 
9 -2 14 No Real Roots 
6 2 10 No Real Roots 

처럼 보이는 그것은 내가받을 컴파일 한 후 인쇄 할 :

[[1, 1, 1], [1, 1, 1, 9, -2, 14], [1, 1, 1, 9, -2, 14, 6, 2, 10]] No Real Roots 
[[1, 1, 1], [1, 1, 1, 9, -2, 14], [1, 1, 1, 9, -2, 14, 6, 2, 10]] No Real Roots 
[[1, 1, 1], [1, 1, 1, 9, -2, 14], [1, 1, 1, 9, -2, 14, 6, 2, 10]] No Real Roots 

왜 라인에 계속 추가합니까?

답변

0

매번 전체 목록을 추가하고 있습니다.

inputList1.append(input1) 
    inputList1.append(input2) 
    inputList1.append(input3) 
    inputListA.append(inputList1[:]) # ouchy 

당신은 아마 이런 식으로 뭔가 의미 :

inputListA.append(inputList1[-3:]) 

어느 쪽이든 또는 각 패스에서 inputListN을 취소 의미한다.

편집 :

은 괄호를 제거하려면 :

format(' '.join([str(i) for i in currentList]), ...) 
+0

딱! 이제 인쇄 할 때 목록 주위에 괄호를 제거하면됩니다. – user3055517