Python颜色输出和random的学习

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

from termcolor import 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')

效果:

知识点:
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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值