还剩2页未读,继续阅读
文本内容:
python小游戏代码import random()def display_instructions:(”欢迎来到石头剪刀布游戏!”)print(游戏规贝」)print I(石头普通攻击”)Hprint
1.(剪刀剪切攻击,可以打败石头”)print
2.(布防护,可以打败剪刀”)nprint
3.(”每一轮游戏,电脑会随机选择石头、剪刀或布)print(如果你想退出游戏,请输入,退出屋”)print()def get_user_choice:(请选择(石头、剪刀或布))user_choice=input”「石头剪刀布」while user_choice notin ll anduser_choice!=退出’(”无效的选择,请重新选择(石头、剪刀或布)或输入,退出,)print”(”请选择(石头、剪刀或布)”)user_choice=inputreturn userchoicedef get_computer_choice:=「石头,剪刀,布choices ll Ureturnrandom.choice choicesdefdetermine_winneruser_choice,computer_choice:退出if user_choice==’游戏结束,你选择了退出”print㊀lif user_choice==computer_choice:“平局!”print’石头,==剪刀elif user_choice==and computer_choice or\’剪刀,==布,㊀㊀user_choice==and computr_choic or\布,==石头㊀㊀user_choice==and computr_choic你赢了!”printelse:你输了!”printreturndef play_game:display_instructions whileTrue:user_choice=get_user_choice退出’if user_choice==breakcomputer_choice=get_computer_choice电脑选择了,print computer_choicedetermine_winneruser_choice computer_choicez谢谢游玩!”printplay_game这个游戏的流程是首先,电脑会显示游戏说明然后,用户会被要求输入他们的选择石头、剪刀或布用户的输入会被检查,如果输入不是“石头”、“剪刀”或“布”,则会被要求重新输入然后,电脑会随机选择一种攻击方式接着,游戏会确定胜者并输出结果如果用户想退出游戏,可以输入“退出”,游戏将结束游戏的循环会一直进行下去,直到用户选择退出。
个人认证
优秀文档
获得点赞 0