看板 Python 關於我們 聯絡資訊
在學校打的程式碼是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
ck574b027:你def的函式不是report_list_does_not_have啊 03/21 13:58
Yukirin:第一個def後面 函數名跟()中間空格拿掉看看 03/21 19:04
kdjf:你的error是什麼? 03/21 20:58
grapherd:把report_does_not_hav 放到 nth_element上面看看 03/21 22:03
grapherd:......兩個函數名稱錯了而已.. 03/21 22:04
b98204030:XDDD我自己也看到了 感謝各位~~ 03/21 23:10
b98204030:還有最後面應該是%d 03/21 23:10