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)
利用random函数写了个小程序。你把输入和输举派出与html元素连接一下应物答该就可以了。#! /user/bin/python
# filename: dicegame.py
import random
total = int(input ('please input your guess number for sum of 6 DICE!'))# int number input.
print ('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
print ('Your lucky number is ',total)
dicenum = 0 # define one integer for sum of 6 dice numbers
L = [] # define one list for dice number display
for i in range(6):
r = random.randint(1,6) # random function to create number between [1,6]
L.append(r)
dicenum += r
print('The dices shows %s ! \nTotal dice summary is %d'正蚂贺 % (L, dicenum))
if total == dicenum: # judge guess num againt real summary
print('\nYou win!')
else:
print('\nPity that you miss it, how about try next lucky?')
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)