2012-04-11 15 views
0

三角形の最大ルートを見つける必要があります。私は以前この投稿Finding the Maximum Route in a given inputを投稿しました。毎回異なる値で複数の試行ができるように実装しています。検索異なる三角形を持つ最大ルート

numOfTries = raw_input("Please enter the number of tries") 
Tries = int(numOfTries) 
for count in range(Tries): 
    numstr= raw_input("Please enter the height:") 
    rows = int(numstr) 
    triangle(rows) 
    routes(triangle) 
    max(routes(triangle),key=sum) 
def triangle(rows): 
    for rownum in range (rows): 
     PrintingList = list() 
     print ("#%d row") % rownum 
     for iteration in range (rownum): 
      newValue = raw_input("Please enter the %d number:") %iteration 
      PrintingList.append(int(newValue)) 
      print() 
def routes(rows,current_row=0,start=0): 
      for i,num in enumerate(rows[current_row]): #gets the index and number of each number in the row 
       if abs(i-start) > 1: # Checks if it is within 1 number radius, if not it skips this one. Use if not (0 <= (i-start) < 2) to check in pyramid 
        continue 
       if current_row == len(rows) - 1: # We are iterating through the last row so simply yield the number as it has no children 
        yield [num] 
       else: 
        for child in routes(rows,current_row+1,i): #This is not the last row so get all children of this number and yield them 
         yield [num] + child 

エラー:

Traceback (most recent call last): 
    File "<pyshell#2>", line 1, in <module> 
    numOfTries = raw_input("Please enter the number of tries") 
NameError: name 'raw_input' is not defined 

すべてのヘルプは高く評価され、私は、私は、Python 3.2.2

コードを使用しています... ..エラーを持っているように見えることにいくつかの助けが必要。

答えて

3

Python3ではraw_input()(Python2バージョン)は現在単純にinput()

です
関連する問題