2012-10-16 12 views
1
import itertools 

class Twentyfour: 
    def __init__(self): 

     self.permutations = [] 
     self.flexIntegers = [] 
     self.flexStrings = [] 

    def Input(self): 

     print("Please print your first number: ") 
     a = input() 
     print("Please print your second number: ") 
     b = input() 
     print("Please print your third number: ") 
     c = input() 
     print("Please print your fourth number: ") 
     d = input() 
     self.permutations = list(itertools.permutations([a,b,c,d]) 

    def Numerical(self, index1, index2, aList): 

     a = float(aList[index1][index2]) + float(aList[index1][index2 + 1]) 
     self.flexIntegers.append[a] 
     b = float(aList[index1][index2]) - float(aList[index1][index2 + 1]) 
     self.flexIntegers.append[b] 
     c = float(aList[index1][index2]) * float(aList[index1][index2 + 1]) 
     self.flexIntegers.append[c] 
     d = float(aList[index1][index2])/float(aList[index1][index2 + 1]) 
     if d%1 != 1.0: 
      useless = 0 
     else: 
      self.flexIntegers.append[d] 

    def String(self, index1, index2, aList): 
     a = "("aList[index1][index2] + "+" + aList[index1][index2 + 1] + ")" 
     self.flexStrings.append[a] 
     b = "("aList[index1][index2] + "-" + aList[index1][index2 + 1] + ")" 
     self.flexStrings.append[b] 
     c = "("aList[index1][index2] + "*" + aList[index1][index2 + 1] + ")" 
     self.flexStrings.append[c] 
     d = "("aList[index1][index2] + "/" + aList[index1][index2 + 1]) + ")" 
     d2 = float(aList[index1][index2])/float(aList[index1][index2 + 1]) 
     if d2%1 != 1.0: 
      useless = 0 
     else: 
      self.flexStrings.append[d] 

對不起,如果這是一個愚蠢的問題,我是Python的noob。 錯誤是當我在Input()之後定義Numerical()時。 有什麼不對嗎? python 3.2 IDLE一直說它是無效的語法。在python中定義這個函數時,我總是收到無效的語法錯誤

回答

1

上一個塊的最後一行缺少一個paren。

1

self.permutations = list(itertools.permutations([a,b,c,d])

你需要另一個括號。 (itertools.permutations([a,b,c,d])是一個,list()是另一個。

+0

沉沒你非常好的先生 –

相關問題