话不多说,一个是算时间的,还有一个是生成验证码的

 #!usr/bin/env/ python
# -*- coding:utf-8 -*-
# Author: XiaoFeng
import time
start_time = "2016-9-1 7:00:00"
handel = time.mktime(time.strptime(start_time, "%Y-%m-%d %H:%M:%S"))
now = time.time()
now_strtime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(now))
print(now_strtime)
dis_time = now - handel
struc_time = time.localtime(dis_time)
print("我已经来这儿\033[41;1m%d年,%d月,%d日,%d小时,%d分钟,%d秒了!\033[0m,好快呀" %
(struc_time.tm_year-1970, struc_time.tm_mon-1, struc_time.tm_mday-1,
struc_time.tm_hour, struc_time.tm_min, struc_time.tm_sec))

验证码:

#!usr/bin/env/ python
# -*- coding:utf-8 -*-
# Author: XiaoFeng
import random def verif_code():
code = []
i = 4
while 1:
times_1 = random.sample(["num", "alpha"], 1)
print(times_1)
if times_1[0] == "num":
num = str(random.randint(0, 9))
code.append(num)
else:
alpha = chr(random.randint(65, 90))
if random.randint(0, 1) == 0:
alpha = alpha.lower()
code.append(alpha)
i -= 1
if i == 0:
return code verification = verif_code()
print(verification)
verification = "".join(verification)
print(verification)
#!usr/bin/env/ python
# -*- coding:utf-8 -*-
# Author: XiaoFeng
import random def verif_code():
code = []
i = 4
while :
times_1 = random.sample(["num", "alpha"], )
print(times_1)
if times_1[] == "num":
num = str(random.randint(, ))
code.append(num)
else:
alpha = chr(random.randint(, ))
if random.randint(, ) == :
alpha = alpha.lower()
code.append(alpha)
i -= 1
if i == :
return code verification = verif_code()
print(verification)
verification = "".join(verification)
print(verification)

python3 时间模块 random模块之两个小练习的更多相关文章

  1. Python模块01/自定义模块/time模块/datetime模块/random模块

    Python模块01/自定义模块/time模块/datetime模块/random模块 内容大纲 1.自定义模块 2.time模块 3.datetime模块 4.random模块 1.自定义模块 1. ...

  2. python常用模块——random模块

    参考博客:http://www.360doc.com/content/14/0430/11/16044571_373443266.shtml 今天突然想起python该怎么生成随机数?查了一下,贴出实 ...

  3. Python进阶(十)----软件开发规范, time模块, datatime模块,random模块,collection模块(python额外数据类型)

    Python进阶(十)----软件开发规范, time模块, datatime模块,random模块,collection模块(python额外数据类型) 一丶软件开发规范 六个目录: #### 对某 ...

  4. python 全栈开发,Day27(复习, defaultdict,Counter,时间模块,random模块,sys模块)

    一.复习 看下面一段代码,假如运行结果有问题,那么就需要在每一步计算时,打印一下结果 b = 1 c = 2 d = 3 a = b+c print(a) e = a + d print(e) 执行输 ...

  5. 常用模块(collections模块,时间模块,random模块,os模块,sys模块,序列化模块,re模块,hashlib模块,configparser模块,logging模块)

    认识模块 什么是模块? 常见的场景:一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀. 但其实import加载的模块分为四个通用类别: 1 使用python编写的 ...

  6. 模块-os.system的两个模块/random模块/datetime模块/写日志

    一.获取当前目录的路径 os.path.abspath('.')# 取绝对路径 os.getcwd()# 取当前路径 .代表当前目录 ..上一级目录 ../.. 二.执行操作系统命令1.os.syst ...

  7. Python3 time模块&datetime模块&random模块

    ''' time模块 ''' # import time # print(help(time)) # help()提供帮助 # print(time.time()) # 1970年开始到现在的秒数(时 ...

  8. 4-24日 collections模块 random模块 time模块 sys模块 os模块

    1, collections模块 在内置数据类型(dict.list.set.tuple)的基础上,collections模块还提供了几个额外的数据类型:Counter.deque.defaultdi ...

  9. python常用模块: random模块, time模块, sys模块, os模块, 序列化模块

    一. random模块  import random # 任意小数 print(random.random()) # 0到1的任意小数 print(random.uniform(-10, 10)) # ...

  10. python-Day5-深入正则表达式--冒泡排序-时间复杂度 --常用模块学习:自定义模块--random模块:随机验证码--time & datetime模块

    正则表达式   语法:             mport re #导入模块名 p = re.compile("^[0-9]") #生成要匹配的正则对象 , ^代表从开头匹配,[0 ...

随机推荐

  1. 【转载】limits.h

    limits.h专门用于检测整型数据数据类型的表达值范围. <limits.h>主要提供对整型和字符型范围的限制的宏,同样没有指定类型和函数的定义. 1.整型宏如下表: 2.字符型宏如下表 ...

  2. IE6的3像素BUG产生条件及解决方法

    1.IE6中第一个元素浮动第二个元素不浮动,这两个元素之间就会产生3像素BUG 2.解决方案: 2.1若若宽度一定则给第二个元素添加 float 样式即可: 2.2若宽度自适应: 2.2.1  _ma ...

  3. PHP cURL使用小结

    cURL简介 cURL是什么? cURL(Client URL Library Functions)由 Daniel Stenberg 创建的libcurl库,官方定义为:curl is a comm ...

  4. PCB 圆形板切边算法 实现

    在工程CAM处理圆形拼板是个头疼的问题,需人工程师自行设计切边 满足可以拼板并且拼板后锣板板边没有内角,不然会影响装配 1.原始单 PCS圆形板 此外形如果不采用邮票孔连接的话,采V-CUT连接须采用 ...

  5. 【weiphp】安装中报错

    问题描述:安装的第三部报错“SQLSTATE[HY000]: General error: 2030 This command is not supported in the prepared sta ...

  6. python自动化测试学习笔记-7面向对象编程,类,继承,实例变量,邮件

    面向对象编程(OOP)术语: class TestClass(object):   val1 = 100       def __init__(self):     self.val2 = 200   ...

  7. SpringMVC实现Action的两种方式以及与Struts2的区别

    4.程序员写的Action可采用哪两种方式? 第一.实现Controller接口第二.继承自AbstractCommandController接口 5.springmvc与struts2的区别? 第一 ...

  8. 405 Convert a Number to Hexadecimal 数字转换为十六进制数

    给定一个整数,编写一个算法将这个数转换为十六进制数.对于负整数,我们通常使用 补码运算 方法.注意:    十六进制中所有字母(a-f)都必须是小写.    十六进制字符串中不能包含多余的前导零.如果 ...

  9. 263 Ugly Number 丑数

    编写程序判断给定的数是否为丑数.丑数就是只包含质因子 2, 3, 5 的正整数.例如, 6, 8 是丑数,而 14 不是,因为它包含了另外一个质因子 7.注意:    1 也可以被当做丑数.    输 ...

  10. System.AppDomain类详解(二)

    进程是存在独立的内存和资源的,但是AppDomain仅仅是逻辑上的一种抽象.一个process可以存在多个AppDomain.各个AppDomain之间的数据时相互独立的.一个线程可以穿梭多个AppD ...