import random
import time
def displayIntro():
print('You are in a land full of dragons. In front of you,')
print('you see two caves. In one cave, the dragon is friendly')
print('and will share his treasure with you. The other dragon')
print('is greedy and hungry, and will eat you on sight.')
print()
def chooseCave():
cave = ''
while cave != '1' and cave != '2':
print('Which cave will you go into? (1 or 2)')
cave = input()
return cave
def checkCave(chosenCave):
print('You approach the cave...')
time.sleep(2)
print('It is dark and spooky...')
time.sleep(2)
print('A large dragon jumps out in front of you! He opens his jaws and...')
print()
time.sleep(2)
friendlyCave = random.randint(1, 2)
if chosenCave == str(friendlyCave):
print('Gives you his treasure!')
else:
print('Gobbles you down in one bite!')
playAgain = 'yes'
while playAgain == 'yes' or playAgain == 'y':
displayIntro()
caveNumber = chooseCave()
checkCave(caveNumber)
print('Do you want to play again? (yes or no)')
playAgain = 2
1
input()
在这里你可以看到正在玩的游戏与人。最后,当你需要回答是或否来再次玩时,再次玩游戏和退出系统的适当编码应该是什么?我有一个类似的问题,我必须编辑另一个游戏,再次播放或不再播放功能。需要完成我的作业代码
感谢B,
谢谢,但你如何触发no功能? – njr0502
如果用户回答“否”(或者是“yes”),程序将退出,这是我所期望的行为。 – domoarrigato