alphabet =["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
def decoder(input):
inputlist = list(input)
inputlength = len(input)
alphabetlength = len(alphabet)
result = "Decoded Sentence: "
for x in range(inputlength):
for y in range(alphabetlength):
if inputlist[x] is alphabet[y]:
print ("hi")
if y == 24:
result += "a"
if y == 25:
result += "b"
else:
result += alphabet[y+2]
if inputlist[x] is "(":
result += "("
if inputlist[x] is ")":
result += ")"
if inputlist[x] is ".":
result += "."
if inputlist[x] is " ":
result += " "
return result
我的代碼應該由2.前遞增一個句子的字母:A-> C,1->ñ 我把打印(「HI」)語句檢查if語句是否被評估爲真,但它從來沒有。有人可以告訴我爲什麼嗎?爲什麼我的if語句不是比較列表項
**'is' **用於身份檢查不平等,但這可能不是唯一的問題。 –
爲了擴展上述內容,檢查它們是否是兩個內存中的相同對象和位置。你想用戶平等「==」不是。 – hankd
Fyi,而不是做一個大量的字母表列表,「輸入字符串」,然後定義字母表爲「list(string.lowercase)'。 –