[問題] 相同的程式碼換電腦後就出現SyntaxError

看板Python作者 (佳佳)時間12年前 (2013/03/21 13:31), 編輯推噓1(106)
留言7則, 5人參與, 最新討論串1/1
在學校打的程式碼是OK的 可是回家後幾安裝python3.3 一樣的程式碼,卻出現error 以下是程式碼 是要讓出現找不到那麼多個數字的時候知道是沒有那麼多個數字 我想要找第n個數字是什麼,但數列中沒有第n個數字 所以最後要顯示這個數列沒有n個數字 請各位大大幫忙解惑,感謝 car = lambda lst : lst [0] cdr = lambda lst : lst [1:] def nth_element (lst, n, ori): ''' nth_element(lst, n) = the n-th element of lst ''' if lst == []: return report_list_does_not_have(ori, n) elif n == 0: return car(lst) else: return nth_element(cdr(lst), n-1, ori) def report_does_not_have(lst, n): print(lst, "does not have &d elements." % (n + 1 + len(lst))) return None -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.165.97.82

03/21 13:58, , 1F
你def的函式不是report_list_does_not_have啊
03/21 13:58, 1F

03/21 19:04, , 2F
第一個def後面 函數名跟()中間空格拿掉看看
03/21 19:04, 2F

03/21 20:58, , 3F
你的error是什麼?
03/21 20:58, 3F

03/21 22:03, , 4F
把report_does_not_hav 放到 nth_element上面看看
03/21 22:03, 4F

03/21 22:04, , 5F
......兩個函數名稱錯了而已..
03/21 22:04, 5F

03/21 23:10, , 6F
XDDD我自己也看到了 感謝各位~~
03/21 23:10, 6F

03/21 23:10, , 7F
還有最後面應該是%d
03/21 23:10, 7F
文章代碼(AID): #1HIfiroy (Python)
文章代碼(AID): #1HIfiroy (Python)