python工作遇到的问题_Python选择文字游戏出现问题(如果-那么陈述无法正常工作)...

# ADDITIONAL DETAILS# This code calculates the damage you would do if you were a heroic knight that is attacking an evil dragon.# You have 6 options available in the main menu: Attack with your sword, attack with magic, block with your shield, Throw a rock at it, Run away, and Quit fight (or exit).# The calculations involve subtracting the attack damage numbers against the dragons HP (or Health Points). For example, if your attack with sword number subtracts the dragons HP number and reaches 0: the dragon will be defeated and the game is “won’.# When the game is won the game is reset back to the main menu (in this case the main menu are the fighting options.)# I hope you find this particular project entry unique and fun!# Main menu function. It should present the options available to input, allow the input of the listed options and be looped until the user uses the quit command.defset_main():sword=set_sword()magic=set_magic()block=set_block()rock=set_rock()run=set_run()done=set_finish()print("Main Menu: ")print("Only one of your attacks can lower his HP to zero! What will you do?! ")print("Type “sword” to use a sword attack with an attack power of 60! ")print("Type “magic” to use a magic attack with an attack power of 80!")print("Type “block” to block with your shield with an attack power of 70! ")print("Type “rock” to throw a rock! with an attack power of ??? ")print("Type “run” to RUN AWAY DUDE! It has an attack power of only 1 though. ")print("Type “done” to finish the game and program. ")# sword attack function that should be called if the input is "sword"defset_sword():sword=str(xString)sword=60dragon=100print('The sum of ',sword,' and ',dragon,' is ',sword-dragon,' Attack power! ',sep='')print("Your Super Special Overlasting Justice Power Sword attack did little damage!")print("The dragon grabs you and eats you whole! Gross.")print("Try Again!")returnset_sword# magic attack function that should be called if the input is "magic"defset_magic():magic=str(xString)magic=80dragon=100print('The sum of ',magic,' and ',dragon,' is ',magic-dragon,' Attack power! ',sep='')print("Your magic attack is too weak!")print("The dragon uses it's mighty feet and stomps on you!")print("So yeah, you're dead. Try again!")returnset_magic# blocking attack function that should be called if the input is "block"defset_block():block=str(xString)block=100dragon=100print('The sum of ',block,' and ',dragon,' is ',block-dragon,' Attack power! ',sep='')print("You blocked the dragon's attack perfectly!")print("Both you and the dragon are exhasuted and decide to fight another day!")print("So uh...Try again tomorrow?")returnset_block# rock throw attack function that should be called if the input is "rock"defset_rock():rock=str(xString)rock=150dragon=100print('The sum of ',rock,' and ',dragon,' is ',rock-dragon,' Attack power! ',sep='')print("In complete desperation you find a rock next to you and throw it at the dragon!")print("The rock hits the drgon square in the eye! It roars in pain!")print("The dragon then begins to cry and it doesn't like things hitting his eye.")print("The dragon then flies away from the castle in fear!")print("So..YOU DID IT! Congratulations! Try one of the other options!")returnset_rock# run command function that should be called if input is "run"defset_run():run=str(xString)run=150dragon=100print('The sum of ',run,' and ',dragon,' is ',run-dragon,' Attack power! ',sep='')print("You decide that saving the world isn't worth it and you run!")print("You decide to retire and leave a peaceful life. You find a nice partner, fall in love, and have children.")print("several years later the dragon storms into your village and wipes out everything!")print("Including you...")print("Was your time of peace worth it? Find out by trying again!")returnset_run# quit function that should quit the program if the user inputs "done"defset_finish():print("Game over! Thanks for playing!")quitreturnset_finish# default introduction print should explain the game and pretends an ending input.print("The hero arrives in the dark castle and is welcomed by a large and evil dragon! You are that hero and must defeat the dragon to save the princess!")print("The Dragon has 100 HP! ")xString=str(input("What attack will you do?! (Type the attack name to pick an attack) :"))ifxString=="sword":print(set_sword())elifxString=="magic":print(set_magic())elifxString=="block":print(set_block())elifxString=="rock":print(set_rock())elifxString=="run":print(set_run())elifxString=="done":print(set_finish())else:print("Pick an option please.")quitprint(set_main())print("Hope you had fun!")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值