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

 #!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. 杂项-Java:JSP

    ylbtech-杂项-Java:JSP 1.返回顶部 1. JSP全名为Java Server Pages,中文名叫java服务器页面,其根本是一个简化的Servlet设计,它是由Sun Micros ...

  2. 在Android.mk文件中输出打印消息 (转载)

    转自:http://blog.csdn.net/xiaibiancheng/article/details/8479694 在进行Android NDK的开发当中有时想看看Android.mk文件当中 ...

  3. Tomcat的jvm配置

    Tomcat本身不能直接在计算机上运行,需要依赖于操作系统和一个JAVA虚拟机.Tomcat的内存溢出本质就是JVM内存溢出,JAVA程序启动时JVM会分配一个初始内存和最大内存给程序.当程序需要的内 ...

  4. mysql的大数据量的查询

    mysql的大数据量查询分页应该用where 条件进行分页,limit 100000,100,mysql先查询100100数据量,查询完以后,将 这些100000数据量屏蔽去掉,用100的量,但是如果 ...

  5. linux C编程 gdb的使用

    linux C编程 gdb的使用 通常来说,gdb是linux在安装时自带的,在命令行键入"gdb"字符并按回车键会启动gdb调试环境. 1.gdb的基本命令 命令 说明 file ...

  6. Spring MVC过滤器-HiddenHttpMethodFilter

    参考来源:http://blog.csdn.net/geloin/article/details/7444321 浏览器form表单只支持GET与POST请求,而DELETE.PUT等method并不 ...

  7. tablespace monitor shell for windows

    1. #! /bin/ksh #set -x SID=$1 ORACLE_SID=stat10gORACLE_HOME=/oracle10g/product/10.2PATH=$PATH:/usr/b ...

  8. 【转】mysql INSERT的用法

    转自:http://www.cnblogs.com/ggjucheng/archive/2012/11/05/2754938.html insert的语法 INSERT [LOW_PRIORITY | ...

  9. Scala-基础-数组(1)

    import junit.framework.TestCase import scala.collection.mutable.ArrayBuffer; //数组(1) //知识点-定义数组,变长数组 ...

  10. CF816B Karen and Coffee

    思路: 有点类似于区间修改点查询的树状数组. 实现: #include <iostream> #include <cstdio> using namespace std; ; ...