whileループを使用するのに問題があります。私がしたいのは、プログラムが実行され、出力が提供されると、プログラムは「翻訳する単語を入力してください」に戻ります。Pythonのループが動作しない
while true
とcontinue
を私が適切な場所と信じて使用したとき、単に出力を続けます。私が翻訳している言葉の希望は意味をなさない。
以下は、私が働いているコードです。 2番目のチャンクは、whileループを追加して問題に取り組む場所です。
def silly_alpha():
print("Looks like we're going with the Impossible alphabet.")
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.")
これは、問題のあるコード
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=' ')
continue
else:
print("There's no numbers in words. Try that again.")
continue
'continue'をまったく使用する必要はありません。 – ettanany
あなたは何を続けると思いますか? – polku
'continue'は、最も内側のブロックを続けます。 'if'の場合の' for'反復と 'else'の場合の' while'です。 –