0
点赞
收藏
分享

微信扫一扫

Python颜色输出和random的学习

颜色输出模块:termcolor
​​​http://pypi.python.org/pypi/termcolor

from termcolor import colored

Python颜色输出和random的学习_colored

random 的 学习:

#!/usr/bin/env python
# -*- encoding: utf-8 -*
import random
from termcolor import colored

buytimes = 1

try:
times = input('想买几注(默认一注): ')
except:
times = 1

while buytimes <= times:

red = map(str,range(1,34))
blue = map(str,range(1,17))
random.shuffle(red)
random.shuffle(blue)

rball = random.sample(red,6)
bball = random.sample(blue,1)

strred = ' '.join(rball)
strblue = ' '.join(bball)

buytimes += 1
print colored(strred,'red') + ' ' + colored(strblue,'blue')

效果:
Python颜色输出和random的学习_random_02

知识点:
random.random()      :返回 0 <= n < 1的随机实数。
random.uniform(a,b) :返回 a <= n < b的随机实数。
random.randrange([start],stop,[step]) :返回range([start],stop,[step])的随机整数。
random.choice(seq)   :返回seq序列中的任意元素。
random.shuffle(seq)  :随机移位。
random.sample(seq,n) :从序列中取n个随机的元素。

 

~~~~~~~~~~~~~~~ 万物之中,希望至美 ~~~~~~~~~~~~~~~

举报

相关推荐

0 条评论