Мой код:Как избежать повторения строк?
import random
WORDS = ('python', 'football', 'facebook', 'photo') #list of words that will be riddled
word = random.choice(WORDS)
correct = word
jumble = ''
hint = 'hint'
score = 0
while word:
position = random.randrange(len(word))
jumble += word[position]
word = word[:position] + word[(position + 1):] #creating jumble of correct words
print('Welcome to the game "Anagrams"')
print('Here`s your anagram:', jumble) #Welcoming and giving a jumble to a player
guess = input('\nTry to guess the original word: ')
if guess == correct:
score += 5
print('You won! Congratulations!') #end of game in case of right answer
if guess == hint: #situation if player asks a hint
if correct == WORDS[0]:
print('snake')
elif correct == WORDS[1]:
print('sport game')
elif correct == WORDS[2]:
print('social network')
elif correct == WORDS[3]:
print('picture of something')
score += 1
while guess != correct and guess != '': #situation if player is not correct
print('Sorry, you`re wrong :(')
guess = input('Try to guess the original word: ')
print('Thank you for participating in game.')
print('Your score is', score)
input('\nPress Enter to end')
Задавая намек строки:.
'К сожалению, you`re неправильно :('
повторы
Это выглядит следующим образом:
Попробуйте угадать оригинальное слово: hint
спортивная игра
К сожалению, you`re неправильно :(
Как сделать эта строка появляется только в случае неправильного предположения?
'в то время как угадать = правильно угадать =«»и думаю:' ' печать! («К сожалению, you're неправильно :(»)' делает именно то, что вы хотите сделать –
я пытался поставить там 'и думаю! = hint' , но в случае завершения этой программы при запросе подсказки – pookeeshtron
Отступ кажется мне неправильным. Это только часть вашей игры? – Wolf