[問題] 相同的程式碼換電腦後就出現SyntaxError
在學校打的程式碼是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
03/21 13:58, 1F
推
03/21 19:04, , 2F
03/21 19:04, 2F
→
03/21 20:58, , 3F
03/21 20:58, 3F
→
03/21 22:03, , 4F
03/21 22:03, 4F
→
03/21 22:04, , 5F
03/21 22:04, 5F
→
03/21 23:10, , 6F
03/21 23:10, 6F
→
03/21 23:10, , 7F
03/21 23:10, 7F
Python 近期熱門文章
PTT數位生活區 即時熱門文章