刚刚写了一个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