안녕하세요 저는 프로그래밍에 완전히 익숙하지 않아서 파이썬을 가르치려고 노력했습니다. 나는 단어를 선택한 다음 편지를 뒤섞어서 사용자가 추측을 입력하도록하는 프로그램을 만들려고 노력했습니다. 3 번 시도합니다. 제가하는 데 문제는 잘못된 대답이 선택한 단어의 편지를 reshuffles 입력 또는 완전히 다른 단어를 반환 할 때 여기 내 코드입니다 :임의의 단어 게임 python 3.5
import random
import sys
##Welcome message
print ("""\tWelcome to the scrambler,
select [E]asy, [M]edium or [H]ard
and you have to guess the word""")
##Select difficulty
difficulty = input("> ")
difficulty = difficulty.upper()
##For counting number of guesses it takes
tries = 0
while tries < 3:
tries += 1
##Starting the game on easy
if difficulty == 'E':
words = ['teeth', 'heart', 'police', 'select', 'monkey']
chosen = random.choice(words)
letters = list(chosen)
random.shuffle(letters)
scrambled = ''.join(letters)
print (scrambled)
guess = input("> ")
if guess == chosen:
print ("Congratulations!")
break
else:
print ("you suck")
else:
print("no good")
sys.exit(0)
당신이 볼 수 있듯이 나는 단지로 들어 왔 아주 쉽게, 나는 조각으로 그것을하려고 노력하고 있었고, 다른 문제들을 극복 할 수 있었다. 그러나 나는 가지고있는 것을 고치는 것처럼 보이지 않는다. 어떤 문제라도 내가 가지고있는 문제 또는 내 코드에서 발견 할 수있는 다른 문제로 인해 도움을받을 수 있습니다.
다음 단어/스크램블 _before_ 재시도 루프를 선택하십시오 ... –
while 루프에 의해 선택되도록 if 블록을 들여 쓸 수 있습니다. – Ohjeah
@Ohjeah 생각했지만 버그 설명에 들여 쓰기가 명확하게 나타났습니다. 게시 할 때 오류가 발생했습니다. –