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 ...
随机推荐
- Java文件实时监控Commons-io
今天看到一网友写的 Java 文件监控,实时监控文件加载 ,突然想到Commons-io中已有此功能的实现,先温习下 写个简单的Demo: 有三种方式: 1.java common.io 内部实 ...
- android 使用AlarmManager定时启动service
private static AlarmManager am; private static PendingIntent pendingIntent; /** * 使用 AlarmManager 来 ...
- POJ1265 Area 多边形内格点数 Pick公式
POJ1265给定一个多边形 计算边上的格点 内部的格点 以及多边形的面积 利用Pick公式 面积=内部格点数+边上格点数/2-1 将多边形分割为三角形容易证得上述公式 计算面积用叉积,计算边上格点 ...
- xargs 主要用于不支持管道的shell命令*****
变量置换,主要用于不支持管道的shell命令,如:rm.sed等,但有些命令需要占位符“{}”需要注意.比如:删除文件- ls|xargs -i rm -rf {} 文件改名- ls|xargs ...
- libnids 中哈希表的建立
//hash.c #include <sys/types.h>#include <sys/time.h>#include <stdio.h>#include < ...
- 2-4 Vue中的属性绑定和双向数据绑定
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- E2017614-hm
pluck n. 勇气,精神; 内脏; 快而猛的拉; 〈俚〉不及格; vt. 拔掉; 采,摘; 鼓起(勇气等); 弹(乐器); scope n. (处理.研究事务的) 范围; 眼界,见识 ...
- bzoj 1426: 收集邮票【期望dp】
我太菜了,看的hzwer的blog才懂 大概是设f[i]表示已经拥有了i张邮票后期望还要买的邮票数,这个转移比较简单是f[i]=f[i]*(i/n)+f[i+1]*((n-i)/n)+1 然后设g[i ...
- bzoj 3534: [Sdoi2014]重建【矩阵树定理】
啊啊啊无脑背过果然不可取 比如这道题就不会写 参考:https://blog.csdn.net/iamzky/article/details/41317333 #include<iostream ...
- codevs1297 硬币(背包dp,方案数)
1297 硬币 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 我们知道即使是同一种面值的硬币,它们的重量也有可能不一样, ...