python3 时间模块 random模块之两个小练习
话不多说,一个是算时间的,还有一个是生成验证码的
#!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模块之两个小练习的更多相关文章
- Python模块01/自定义模块/time模块/datetime模块/random模块
Python模块01/自定义模块/time模块/datetime模块/random模块 内容大纲 1.自定义模块 2.time模块 3.datetime模块 4.random模块 1.自定义模块 1. ...
- python常用模块——random模块
参考博客:http://www.360doc.com/content/14/0430/11/16044571_373443266.shtml 今天突然想起python该怎么生成随机数?查了一下,贴出实 ...
- Python进阶(十)----软件开发规范, time模块, datatime模块,random模块,collection模块(python额外数据类型)
Python进阶(十)----软件开发规范, time模块, datatime模块,random模块,collection模块(python额外数据类型) 一丶软件开发规范 六个目录: #### 对某 ...
- python 全栈开发,Day27(复习, defaultdict,Counter,时间模块,random模块,sys模块)
一.复习 看下面一段代码,假如运行结果有问题,那么就需要在每一步计算时,打印一下结果 b = 1 c = 2 d = 3 a = b+c print(a) e = a + d print(e) 执行输 ...
- 常用模块(collections模块,时间模块,random模块,os模块,sys模块,序列化模块,re模块,hashlib模块,configparser模块,logging模块)
认识模块 什么是模块? 常见的场景:一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀. 但其实import加载的模块分为四个通用类别: 1 使用python编写的 ...
- 模块-os.system的两个模块/random模块/datetime模块/写日志
一.获取当前目录的路径 os.path.abspath('.')# 取绝对路径 os.getcwd()# 取当前路径 .代表当前目录 ..上一级目录 ../.. 二.执行操作系统命令1.os.syst ...
- Python3 time模块&datetime模块&random模块
''' time模块 ''' # import time # print(help(time)) # help()提供帮助 # print(time.time()) # 1970年开始到现在的秒数(时 ...
- 4-24日 collections模块 random模块 time模块 sys模块 os模块
1, collections模块 在内置数据类型(dict.list.set.tuple)的基础上,collections模块还提供了几个额外的数据类型:Counter.deque.defaultdi ...
- python常用模块: random模块, time模块, sys模块, os模块, 序列化模块
一. random模块 import random # 任意小数 print(random.random()) # 0到1的任意小数 print(random.uniform(-10, 10)) # ...
- python-Day5-深入正则表达式--冒泡排序-时间复杂度 --常用模块学习:自定义模块--random模块:随机验证码--time & datetime模块
正则表达式 语法: mport re #导入模块名 p = re.compile("^[0-9]") #生成要匹配的正则对象 , ^代表从开头匹配,[0 ...
随机推荐
- CollapsingToolbarLayout Toolbar的title覆盖问题
CollapsingToolbarLayout 里: 1 2 app:titleEnabled="true" app:title="Hello" Toolbar ...
- JQuery操作下拉框
转载自下面的链接,很有用的. http://www.cnblogs.com/yrhua/archive/2012/11/04/2753571.html 要实现这种效果: HTML代码 <scri ...
- Enum类的非一般用法汇总(工作中遇到时持续更新)
1. 每个枚举实例定义一套自己的方法示例: 1 @AllArgsConstructor 2 public enum BroadcastTypeEnum { 3 ALL(0, "全站&quo ...
- springmvc 用fasterxml.jackson返回son数据
一,引入fasterxm.jackson包 <dependency> <groupId>com.fasterxml.jackson.core</groupId> & ...
- tar zxvf 解压文件提示错误
1.tar -zxvf 提示错误 2. 查看文件之后发现是html格式的.file **(文件名) 3.原来是直接之前sudo wget url ...url连接错误了. 这个url直接在jdk哪里, ...
- PCB 帆软FineReport安装,布署,配置
公司使用帆软FineReport做为报表平台工具也有一年多时间,而FineReport报表平台与Tomcat Web应用服务是站队在java阵营里,因为相信拥抱微软;.net未来发展会越来越好,所以对 ...
- [App Store Connect帮助]五、管理构建版本(1)上传构建版本概述
在您添加 App 至您的帐户之后,您可以使用 Xcode 或 Application Loader 来上传构建版本.稍后,您可以随着您 App 的更改上传更多构建版本.分发构建版本以供测试,或提交您的 ...
- ACM_发工资(简单贪心)
发工资咯: Time Limit: 2000/1000ms (Java/Others) Problem Description: 作为广财大的老师,最盼望的日子就是每月的8号了,因为这一天是发工资的日 ...
- 389 Find the Difference 找不同
给定两个字符串 s 和 t,它们只包含小写字母.字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母.请找出在 t 中被添加的字母.示例:输入:s = "abcd"t = ...
- SQL server存储过程及触发器基础
存储过程:就像函数一样的会保存在数据库中-->可编程性 --> 存储过程-----------------------------------------------------创建存储过 ...