-1
# 5.- match_ends
# Given a list of strings, return the count of the number of
# strings where the string length is 2 or more and the first
# and last chars of the string are the same.
# Note: python does not have a ++ operator, but += works.
# For example, the result of n = n + 1 can be also achieved by n += 1.
def match_ends(words):
# +++your code here+++
if len(words)>=2:
return words[0]and words[-1:]==words[-1:]
words+=words
你們認爲我做錯了什麼,我應該如何改善呢?python程序與match_ends
這裏的結果:
match_ends
X got: True expected: 3
X got: '' expected: 2
OK got: True expected: 1
聽起來像一個家庭作業,並且大部分代碼都是錯誤的。例如,你認爲'len(文字)'做了什麼?什麼是'字[0]'?注意:有一個交互式shell,你可以嘗試大部分的東西。 –
其谷歌python類鍛鍊:) –