偶尔去买双色球,每次购买时都是随机选球,自己平时就用python,当然一直在学习,所以就用python写了一个随机或指定出双色球的脚本。
代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#!/usr/bin/python
# -*- coding=utf-8 -*-
# by author San at 2016-03-03
import
random
import
sys
def
CaiSeQiu(num
=
1
):
''' The function CaiSeQiu is random six numbers for read boll.
one boll for blue.Default are six read boll and one blue
boll.
'''
num
=
int
(num)
p
=
1
print
(
"随机生成 %s 注球:\n"
)
%
num
while
p <
=
num:
LAN
=
[]
L
=
[]
while
len
(L) <
=
5
:
L
=
LAN.append(random.randrange(
1
,
34
))
L
=
sorted
(
set
(LAN))
BLUE
=
random.randrange(
1
,
17
)
print
(
"红球: %s, 蓝球: %s"
)
%
(L,BLUE)
p
+
=
1
#########手动输入生成双色球#########
def
InserQiu(r1,r2,r3,r4,r5,r6,b1):
'''Function InserQiu for Insert seven numbers with read bolls,
The last one is blue boll range in 1,16;The read's
boll range 1,33;
'''
RedQius
=
range
(
1
,
34
)
BludQius
=
range
(
1
,
17
)
print
(
"红球范围:\n %s"
)
%
RedQius
print
(
"蓝球范围:\n %s"
)
%
BludQius
print
Input
=
[r1,r2,r3,r4,r5,r6,b1]
RL
=
sorted
(
list
(
set
(
Input
[
0
:
6
])))
BL
=
Input
[
-
1
]
if
BL
in
BludQius:
BLQ
=
BL
for
R
in
RL:
if
R
not
in
RedQius:
print
(
"输入的红球不对,请重新输入"
)
sys.exit()
if
len
(RL) <
6
:
print
(
"输入的红球有重复,请输入6个没有重复红球~"
)
sys.exit()
print
(
"你手选的红球: %s,蓝球: %s"
)
%
(RL,BLQ)
if
__name__
=
=
'__main__'
:
try
:
num
=
sys.argv[
1
]
except
IndexError:
print
(
"请输入彩票注数(默认给一注): "
)
CaiSeQiu(
1
)
sys.exit()
else
:
if
not
num.isdigit()
or
sys.argv[
1
] <
=
0
:
print
"出错,请给出正确的票数~ - _ - ~"
sys.exit()
CaiSeQiu(num)
|
直接运行脚本生成一注如图:
导入输入指定数
以上是为了练习写出的冗长的代码,哈哈,其实有简单的,来看看
交互模式下:
1
2
3
4
|
>>>RedQiu
=
sorted
(random.sample(
range
(
1
,
34
),
6
))
>>>BlueQiu
=
random.sample(
range
(
1
,
17
),
1
)
>>>
print
(RedQiu,BlueQiu)
([
4
,
8
,
11
,
22
,
31
,
32
], [
13
])
|
赶紧试试,去买一注吧,万一中了呢?呵呵~