2015-10-20 66 views
-2
building = [["Farm","-1","0","F","1","1","-1"], 
      ["Plot","0","0","P","1","0","-1"], 
      ["House","20","4","H","0","0","5"]] 

cmd = input(">") 
if (cmd == "build"): 
     c = 0 
     length = len(building) 
     while (c < length): 
     bu = building(c) 
     print(c + ") " + bu[0]) 
     c = c + 1 

請幫忙!這個python代碼有什麼問題?請告訴我如何修復它

順便說一句,使用e = sys.exc_info()我得到:

(<class 'TypeError'>, TypeError("'builtin_function_or_method' object is not 
subscriptable",), <traceback object at 0x7f3393e23d88>) 
+1

請分享更多的代碼。你想完成什麼? –

+1

什麼是「建築」?你能分享更多的堆棧跟蹤嗎? – AChampion

+0

什麼在建築?嘗試打印(類型(建設)) –

回答

0

在這裏,你有你的固定代碼:

building = [ ["Farm","-1","0","F","1","1","-1"], ["Plot","0","0","P","1","0","-1"], ["House","20","4","H","0","0","5"]] 
cmd = input(">") 

if (cmd == "build"): 
     c = 0 
     length = len(building) 
     while (c < length): 
      bu = building[c] 
      print(str(c) + ") " + bu[0]) 
      c = c + 1 

什麼是固定的:
- 縮進
- 調用列表建設 - ()而不是[]
- str(c)在print中,因爲c是一個int,所以你不能使用e = sys.exc_info()

0

和整數和字符串

此外,import sys之前,我想通了!我導入了一個使用相同名稱作爲函數的python文件!

相關問題