您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 市场营销 > Python-剪刀石头布游戏
importrandomdefname_to_number(name):ifname==石头:return0elifname==剪刀:return1elifname==布:return2else:return-1defnumber_to_name(number):ifnumber==0:return石头elifnumber==1:return剪刀elifnumber==2:return布else:return石头whileTrue:print(石头剪刀布游戏开始!)print(输入'石头'、'剪刀'或'布',输入'结束'游戏结束。)cmd=input(请出拳:)ifcmd=='结束':print(游戏结束。)breakplayer_number=name_to_number(cmd)ifplayer_number==-1:print(出拳无效,游戏重新开始。)print(--------------------------------------\n)continueprint(你出的拳是:+cmd)computer_number=random.randrange(0,3)print(电脑出的拳是:+number_to_name(computer_number))diff_mod_three=(player_number-computer_number)%3ifdiff_mod_three==0:print(你和电脑平手!)print(--------------------------------------\n)elifdiff_mod_three==1:print(电脑获胜!)print(--------------------------------------\n)else:print(你获胜!)print(--------------------------------------\n)
本文标题:Python-剪刀石头布游戏
链接地址:https://www.777doc.com/doc-7333873 .html