擅长:python、mysql、java
<p>要让它重复循环,并接受一个新词进行翻译,只需删除那些<code>continue</code>语句。我在IDLE中测试了这个,效果很好。你知道吗</p>
<pre><code>def silly_alpha():
print("Looks like we're going with the Impossible alphabet.")
while True:
word_trans = input('Please enter the word you wish to translate: ')
if word_trans.isalpha():
for letter in word_trans:
print(impossible.get(letter.lower()), end=' ')
else:
print("There's no numbers in words. Try that again.")
</code></pre>
<p>但是,现在有一个无限循环。您可能需要考虑允许用户输入终止循环的命令的某种方式。可能是这样的:</p>
<pre><code>def silly_alpha():
print("Looks like we're going with the Impossible alphabet.")
while True:
word_trans = input('Please enter the word you wish to translate, "x" to cancel: ')
if word_trans == 'x':
print('Exiting translation...')
break
elif word_trans.isalpha():
for letter in word_trans:
print(impossible.get(letter.lower()), end=' ')
else:
print("There's no numbers in words. Try that again.")
</code></pre>