python(游戏:骰子)


(Game: craps)Craps is a popular dice game played in casinos. Write a program toplay a variation of the game, as follows:
Roll two dice.Each die has six faces representing values 1,2, .... and 6, respec-tively.Check the sum of the two dice.If the sum is 2,3, or 12(called craps), youlose; if the sum is 7 or 11 (called natural), you win; if the sum is another value(i.e.,4,5,6,8,9, or 10), a point is established.Continue to roll the dice until eithera 7 or the same point value is rolled. If 7 is rolled, you lose.Otherwise,you win.Your program acts as a single player. Here are some sample runs.
 

def youxi():
    x1, x2 = map(int, input().split());
    if x1+x2==7 or x1+x2==11:
        print("You rolled %d+%d=%d"%(x1,x2,x1+x2));
        print("You win");
    elif x1+x2==2 or x1+x2==3 or x1+x2==12:
        print("You rolled %d+%d=%d" % (x1, x2, x1 + x2));
        print("You lose");
    else:
        print("You rolled %d+%d=%d" % (x1, x2, x1 + x2));
        print("point is %d"%(x1+x2));
        a=x1+x2;
        x1,x2=map(int,input().split());
        print("You rolled %d+%d=%d" % (x1, x2, x1 + x2));
        if(x1+x2==7):
            print("You lose");
        else:
            print("You win")

youxi()
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值