剛剛寫了一個python程序來確定助記符「I before E before except C after」的助記符是多麼有用。我在E程序不工作之前
隨着輸入:
'I before e except when conducting an efficient heist on eight foreign neighbors. I believe my friend has left the receipt for the diet books hidden in the ceiling'
它會顯示:
Number of times the rule helped: 5
Number of times the rule was broken: 5
改變了一些事情,我想我改回來,但現在的代碼被打破,任何意見將有助於
while True:
line = input("Line: ")
count = 0
h = 0
nh = 0
words = line.split()
for x in range(0, len(words)):
word = words[count]
if "ie" in word:
if "cie" in word:
nh += 1
else:
h +=1
if "ei" in word:
if "cei" in word:
h += 1
else:
nh += 1
else:
h += 0
count += 1
print("Number of times the rule helped:",h)
print("Number of times the rule was broken:",nh)
print()
也許x應該做索引,不算? – user3125280 2014-10-20 02:30:58
歡迎來到Stackoverflow。我們不是在這裏傾訴你的整個計劃,並猜測問題可能是什麼。請提供具體信息,說明代碼爲什麼「破碎」。有沒有一個測試案例沒有解決?如果是這樣,給我們所有的細節。 – 2014-10-20 02:30:59
抱歉沒有提供足夠的信息,我在這裏仍然很新。發生了什麼事情是我之前發佈的輸入沒有規則的幫助或破壞,從返回答案的意義上來說沒有任何迴應。 但是,它仍檢測較小輸入中的規則破壞/跟蹤。我不知道爲什麼或者如何,但我認爲我已經打破了for循環或邏輯 – user3699151 2014-10-20 03:07:31