|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import random
b = []
r = []
b.append(random.randint(1,16))
r.append(random.randint(1,33))
for i in range(5): #获取后面五个值
lenght = len(r)
for i in range(lenght):
get = r.pop()
while True:
new = random.randint(1,33)
if new == get:
r.append(str(get)[0])
continue
else:
r.append(str(get)[0])
r.append(str(new))
break
ball = {}
ball['红球1'] = r.pop()
ball['红球2'] = r.pop()
ball['红球3'] = r.pop()
ball['红球4'] = r.pop()
ball['红球5'] = r.pop()
ball['红球6'] = r.pop()
ball['蓝球'] = b.pop()
print(ball.items())
print('红球:%s , %s , %s , %s ,%s , %s' % (ball.get('红球1'),ball.get('红球2'),ball.get('红球3'),ball.get('红球4'),ball.get('红球5'),ball.get('红球6')))
print('蓝球:%d' % ball.get('蓝球'))
del random
del ball
del b
del r
我本想做一个双色球彩票的机选,但是!号码中偶尔会有几个球出现重复的情况,若是那位大侠能出手相助,本人定感激不尽!
例如这一次:红球:26 , 2 , 2 , 2 ,4 , 2
这样试试:
import random
b = []
r = []
b.append(random.randint(1, 16))
r.append(random.randint(1, 33))
set_r = set(r)
while len(set_r) < 6:
lenght = len(r)
for i in range(lenght):
get = r.pop()
while True:
new = random.randint(1, 33)
if new == get:
r.append(str(get)[0])
continue
else:
r.append(str(get)[0])
r.append(str(new))
break
set_r = set(r)
r = list(set_r)
ball = {'红球1': r.pop(), '红球2': r.pop(), '红球3': r.pop(), '红球4': r.pop(),
'红球5': r.pop(), '红球6': r.pop(), '蓝球': b.pop()}
print(ball.items())
print('红球:%s , %s , %s , %s , %s , %s' % (
ball.get('红球1'), ball.get('红球2'), ball.get('红球3'),
ball.get('红球4'), ball.get('红球5'), ball.get('红球6')))
print('蓝球:%d' % ball.get('蓝球'))
del random
del ball
del b
del r
|
|