Форум сайта python.su
0
Недавно начал изучать Python. И вот столкнулся со сложностями при изучении циклов. На данном примере - игра “Анаграмма” не могу добиться того, чтобы программа при подсказке предлагала ввести корректный ответ, а не переключалась на новое слово. Задача конечно может и не сложная, но пока что не могу понять где ошибся. Пожалуйста подскажите?)
import random score = 0 score_max = int(input("Enter the maximum score:")) hint = "" while score < score_max: WORDS = ('towel', 'sword', 'ancient', 'club', 'monitor', 'computer', 'coffee', 'school', 'programm', 'service') word = random.choice(WORDS) correct = word jumble = '' while word: position = random.randrange(len(word)) jumble += word[position] word = word[:position] + word[(position + 1):] print("\nHere is Anagramm: ", jumble) guess = str.lower(input("\nTry to guess what word is it:")) while guess != correct and guess != '': print('Your answer is wrong!') hint = str.lower((input('Take a hint? (Yes/No)'))) if hint == 'yes': score -= 5 if correct == 'towel': print('The hint is: t...l') elif correct == 'sword': print('The hint is: s...d') elif correct == 'ancient': print('The hint is: a.....t') elif correct == 'club': print('The hint is: c..b') elif correct == 'monitor': print('The hint is: m.....r') elif correct == 'computer': print('The hint is: c......r') elif correct == 'coffee': print('The hint is: c....e') elif correct == 'school': print('The hint is: s....l') elif correct == 'programm': print('The hint is: p......m') elif correct == 'service': print('The hint is: s.....e') if guess == correct: score += 10 print("CORRECT!!! Your score:", score)
Офлайн
4
Привет!
В последнем цикле while вы выводите на экран подсказку, но не даёте возможность ввести исправленный ответ.
добавьте после команд print возможность правильно ответить на вопрос:
примерно так
elif correct == ‘service’:
print('The hint is: s…..e')
guess = str.lower(input(“\nTry to guess what word is it:”))
if guess == correct:
score += 10
print(“CORRECT!!! Your score:”, score)
Офлайн
0
Ну да) ошибка то была на виду
спасибо!
Офлайн