0
你好,我想知道是否有什麼辦法可以有一個循環被打破,我試圖用break命令,但並不做任何事情。我對此很新。劊子手遊戲,環斷裂和sys.exit
此外,有沒有什麼辦法讓它正常關閉,當人們使用使用命令:
wannaplay = raw_input('Wanna play hangman?(yes or no): ')"
我試過sys.exit這使得例外。
繼承人我的代碼:
import random
import sys
play = 'yes'
while play is 'yes':
word = ['adult','pen','apple']
secret = random.choice(word)
guesses = ''
turns = 5
alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
'adult','pen','apple']
wannaplay = ''
done = False
while(done is False):
wannaplay = raw_input('Wanna play hangman?(yes or no): ')
while(done is not True):
if (wannaplay == 'yes'):
while turns > 0:
missed = 0
for letter in secret:
if letter in guesses:
print letter,
else:
print '_',
missed += 1
print
if missed == 0:
print 'You win!'
done = True
break
break
guess = raw_input('guess a letter: ')
guesses += guess
if guess not in alphabet:
print 'error: Not a letter'
else:
break
if guess not in secret:
turns -= 1
print 'Nope.'
print turns, 'more turns'
if turns == 0:
print 'The answer is', secret
else:
done = True
break
else:
done = True
break
你應該檢查你的行縮進。請嘗試編輯您的代碼並更正它。使用4個空格縮進 – joaquin
sys.exit()給你什麼異常?在我修改你的間距後,我沒有任何問題。 http://pastebin.com/VMsEm0cK – cdated