これは宿題の質問で、「単語を選んでください。ユーザーに文字を入力してもらいます。文字が単語に何回含まれているかを確認し、画面に数字を出力してください。」と尋ねられます。これまでのところ、私はそれをそのまま書きました、そしてそれはうまく働いているようです:
word = str("python")
letters = len(word)
attempt = str(raw_input ("Enter a letter: "))
while attempt in word:
count = "python".count(attempt)
if attempt in word:
print "This letter is present ",count, "time(s)."
attempt = str(raw_input ("Enter another letter: "))
while attempt not in word:
attempt = str(raw_input ("This letter is not present, enter another letter: "))
count = "python".count(attempt)
if attempt in word:
print "This letter is present ",count, "time(s)."
しかし、文字を入力していると、プログラムが停止し、入力を受け取らなくなることがあります。私は何が間違っているのですか?私はプログラミングに不慣れであるため、コードが非常にずさんで、記述が不十分である場合は、お詫び申し上げます。ありがとう。