내 프로그램을 파이썬으로 작성하는 데 도움이 필요합니다. 2.7. 내 문제는 사용자가 '예'를 입력하면 프로그램을 다시 시작하는 방법을 모르겠다는 것입니다. 여기 내 프로그램이 있습니다 :Python 2.7의 프로그램
import random
#Set up the lists for charades and the answers (words)
charadelist = ["Mary's father has 5 daughters: Chacha, Chichi, Cheche, Chocho. What is the name of the 5th daughter?"]
wordlist = ["Mary"]
lencharades = len(charadelist)
lenwords = len(wordlist)
rndnum = random.randrange (0, lenwords)
answer = wordlist[rndnum]
charade = charadelist[rndnum]
print "***Welcome to Charades!***"
print "You are given a charade. Try to guess the answer:"
print '"'+charade+'"'
guess = raw_input('Your answer: ')
if guess == answer:
print "Well done!"
else:
print "Sorry, the correct answer is " + '"'+answer+'"' + '.'
print 'Do you want to play again?'
reply = raw_input('Type `yes` or `no`: ')
if reply == 'yes':
# How do I run the program again??? Please help
if reply == 'no':
print 'Thanks for playing!'
exit
고마워요.
import random
def runGame():
#Set up the lists for charades and the answers (words)
charadelist = ["Mary's father has 5 daughters: Chacha, Chichi, Cheche, Chocho. What is the name of the 5th daughter?"]
wordlist = ["Mary"]
lencharades = len(charadelist)
lenwords = len(wordlist)
rndnum = random.randrange (0, lenwords)
answer = wordlist[rndnum]
charade = charadelist[rndnum]
print "***Welcome to Charades!***"
print "You are given a charade. Try to guess the answer:"
print '"'+charade+'"'
guess = raw_input('Your answer: ')
if guess == answer:
print "Well done!"
else:
print "Sorry, the correct answer is " + '"'+answer+'"' + '.'
reply = ""
while reply != 'no':
runGame()
print 'Do you want to play again?'
reply = raw_input('Type `yes` or `no`: ')
if reply == 'no':
print 'Thanks for playing!'
안녕하세요! 에 오신 것을 환영합니다. 당신은 루프를 찾고 있습니다. 이 질문은 누구에게나 도움이되지 않습니다. 루프와 함수에 대한 파이썬 자습서를 살펴보십시오. – rll