Уведомления

Группа в Telegram: @pythonsu

#1 Апрель 5, 2019 17:30:02

san_911
Зарегистрирован: 2016-07-13
Сообщения: 5
Репутация: +  0  -
Профиль   Отправить e-mail  

Помогите разобраться с работой цикла

Недавно начал изучать 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)

Офлайн

#2 Апрель 5, 2019 19:18:41

panama555
Зарегистрирован: 2019-02-19
Сообщения: 175
Репутация: +  4  -
Профиль   Отправить e-mail  

Помогите разобраться с работой цикла

Привет!
В последнем цикле 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)


Офлайн

#3 Апрель 5, 2019 22:41:10

san_911
Зарегистрирован: 2016-07-13
Сообщения: 5
Репутация: +  0  -
Профиль   Отправить e-mail  

Помогите разобраться с работой цикла

Ну да) ошибка то была на виду спасибо!

Офлайн

Board footer

Модераторировать

Powered by DjangoBB

Lo-Fi Version