Python接口自动化测试框架(练习篇)作业2 猜拳

import random

def quan():
    try:
        guess=int(input("输入你要出的拳:石头(1)/剪刀(2)/布(3)/退出(4)>>>"))
        if guess <=4 and guess >=1:
            return guess
        else:
            print("输错了,请重新输>>>")
            s=quan()
            return s
    except ValueError:
        print("输错了,请重新输>>>")
        s=quan()
        return s
    
if __name__ == '__main__':
    guess_dic={1:"石头",2:"剪刀",3:"布"}

    while True:
        guess=random.randint(1,3)
        guess_vs=quan()
        if guess==guess_vs:
            print("平局。你出拳{0},电脑出拳{1}".format(guess_dic.get(guess_vs),guess_dic.get(guess)))
        elif guess_vs==4:
            print("退出游戏。")
            break
        elif (guess_vs==1 and guess == 2)or (guess_vs==2 and guess == 3)or (guess_vs==3 and guess == 1):
            print("赢了!你出拳{0},电脑出拳{1}".format(guess_dic.get(guess_vs),guess_dic.get(guess)))
        else:
            print("输了!你出拳{0},电脑出拳{1}".format(guess_dic.get(guess_vs),guess_dic.get(guess)))
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值