import random,time
def randstr(x):
num=int(random.uniform(1,7))
return [num,"第" + str(x) + "个骰子摇出来的点如掘穗数是:" + str(num) + "\n"]
def tous(r):
sum,constr=0,""
# range(r) means 0 to r so use below
for i in range(1,r+1):
conresult=randstr(i)
sum+=conresult[0]
constr+=conresult[1]
return [sum,constr]
def calltous(k,v):
daxiao=("点数为小","点数为大渣卜")
result=tous(k)
print result[1] + "所有骰子摇得的总数是:" + str(result[0]) + "\n" + daxiao[(result[0]-v)>0] + "散帆\n"
while True:
calltous(3,10)
time.sleep(1.3)
#include<stdio.h>#include<stdlib.h>
#include<time.h>
int 族歼渣main(void)
{
int ai[3] //甲的三个骰子的点数
int bi[3] //乙的三个骰子的点数
int i
srand((unsigned)time(NULL)) //播时间种子,产生随机数
for (i = 0 i < 3 i++)
{
ai[i] = rand() % 6 + 1 //随兆悄机产生1-6的点数
bi[i] = rand() % 6 + 1
}
printf("甲的点数:")
for (i = 0 i<3 改慧i++)
{
printf("%d ", ai[i])
}
printf("\n乙的点数:")
for (i = 0 i<3 i++)
{
printf("%d ", bi[i])
}
if (ai[0] + ai[1] + ai[2]>bi[0] + bi[1] + bi[2])
{
printf("\n\n甲获胜.\n")
}
else{
printf("\n\n乙获胜.\n")
}
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)