|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
求大神解答,为何while程序不工作
想要输入1 或者2 才执行下去,但是输入3或者其他也能继续执行下去,按照书上敲的代码 不懂为什么不行,求各位大神解答,谢谢谢谢
def chooseCave():
cave = ''
while cave != '1' and cave != '2':
print('which cave will you go into?( 1 or 2)')
cave =input()
return cave
全部源代码
import random
import time
def displayIntro():
print('''you are in a land full of dragons.in front of you,
you see two caves. In one cave,the dragon is friendly
and will share his treasure with you.The other dragon
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 traesure!')
else:
print('gbbles 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 = input() |
|