Python颜色输出和random的学习
2013-01-28 16:42
429 查看
颜色输出模块:termcolor
http://pypi.python.org/pypi/termcolor
random 的 学习:
效果:
知识点:
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个随机的元素。
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个随机的元素。
相关文章推荐
- Python3学习之使用Print输出带颜色字体方法步骤详解
- Python学习笔记之格式化输出
- ①Python学习之输出菱形
- Python学习笔记2-Python神奇的语法和格式化输出
- Python3基础 while配合random输出10个随机整数
- Python3.6 模块学习之random模块
- Python模块学习 ---- random 随机数生成
- Python输出字符串或文件颜色显示
- python之MySQL学习——输出指定条件的结果集
- Python学习:输出99乘法口诀表
- python学习之 输入 输出
- Python学习笔记:详解random模块和time模块
- Python 格式化输出 ( 颜色 )
- python学习-转换物体颜色
- Python设置控制台输出文字的颜色
- python中高亮带颜色输出
- Python学习心得(五) random生成验证码、MD5加密、pickle与json的序列化和反序列化
- Python入门学习之---------Python数字表达式和输出
- python学习002-Python print 输出不换行
- python 学习记录(5)-变量、模块名的命名规则及random模块使用