(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()
本文详细介绍了如何用Python编写一个简单的赌场游戏Craps的版本,包括骰子投掷规则、胜负判断和点数设定,通过实例演示了游戏流程。
1058

被折叠的 条评论
为什么被折叠?



