生成指定长度的随机数字密码
生成指定长度的随机字母密码
生成指定长度的随机数字和字母的混合

#encoding=utf-8

 

import random

import string

class password_generator:

    password_time=0

 

    def __init__(self,length):

        self.length=length

 

    def digital_password(self):

        password_generator.password_time+=1

        s=""

        for i in range(self.length):

            s+=str(random.randint(0,9))

        return s

 

 

    @classmethod

    def letter_password(cls,length):

        password_generator.password_time+=1

        s=""

        for i in range(length):

            s+=str( random.choice(string.letters))

        return s

 

 

 

    @staticmethod

    def letter_mix_digital_password(length):

        password_generator.password_time+=1

        s=""

        s1=""

        nbr=random.randint(0,length)

        for i in range(nbr):

            s+=str( random.choice(string.letters))

        for i in range(length-nbr):

            s1+=str( random.randint(0,9))

        return s+s1

 

 

a=password_generator(10)

print a.length

print a.digital_password()

print password_generator.letter_password(10)

print a.letter_mix_digital_password(10)

 

print "total password:",password_generator.password_time

c:\Python27\Scripts>python task_test.py

10

4775220675

xhqpSYbgGj

TjDIZwuB19

total password: 3

python写一个密码生成器的类,要求有个类变量,统计一下一共生成过多少个密码。 要求有4个方法,1:构造方法 2 实例方法 3 类方法 4 静态方法的更多相关文章

  1. 用Python写一个随机密码生成器

    # /bin/python3 import sys import time import random strs = [ i for i in range(32,128) ] #产生密码的ASCII码 ...

  2. Python 实例方法、类方法、静态方法的区别与作用

    Python中至少有三种比较常见的方法类型,即实例方法,类方法.静态方法.它们是如何定义的呢?如何调用的呢?它们又有何区别和作用呢?且看下文. 首先,这三种方法都定义在类中.下面我先简单说一下怎么定义 ...

  3. 用Python写一个简单的Web框架

    一.概述 二.从demo_app开始 三.WSGI中的application 四.区分URL 五.重构 1.正则匹配URL 2.DRY 3.抽象出框架 六.参考 一.概述 在Python中,WSGI( ...

  4. Python写一个自动点餐程序

    Python写一个自动点餐程序 为什么要写这个 公司现在用meican作为点餐渠道,每天规定的时间是早7:00-9:40点餐,有时候我经常容易忘记,或者是在地铁/公交上没办法点餐,所以总是没饭吃,只有 ...

  5. python写一个能变身电光耗子的贪吃蛇

    python写一个不同的贪吃蛇 写这篇文章是因为最近课太多,没有精力去挖洞,记录一下学习中的收获,python那么好玩就写一个大一没有完成的贪吃蛇(主要还是跟课程有关o(╥﹏╥)o,课太多好烦) 第一 ...

  6. 十行代码--用python写一个USB病毒 (知乎 DeepWeaver)

    昨天在上厕所的时候突发奇想,当你把usb插进去的时候,能不能自动执行usb上的程序.查了一下,发现只有windows上可以,具体的大家也可以搜索(搜索关键词usb autorun)到.但是,如果我想, ...

  7. [py]python写一个通讯录step by step V3.0

    python写一个通讯录step by step V3.0 参考: http://blog.51cto.com/lovelace/1631831 更新功能: 数据库进行数据存入和读取操作 字典配合函数 ...

  8. 【Python】如何基于Python写一个TCP反向连接后门

    首发安全客 如何基于Python写一个TCP反向连接后门 https://www.anquanke.com/post/id/92401 0x0 介绍 在Linux系统做未授权测试,我们须准备一个安全的 ...

  9. 用python写一个自动化盲注脚本

    前言 当我们进行SQL注入攻击时,当发现无法进行union注入或者报错等注入,那么,就需要考虑盲注了,当我们进行盲注时,需要通过页面的反馈(布尔盲注)或者相应时间(时间盲注),来一个字符一个字符的进行 ...

随机推荐

  1. python获取windows所有com口

    import serial import serial.tools.list_ports port_list = list(serial.tools.list_ports.comports()) po ...

  2. DevOps之持续交付

    持续交付 持续交付是一种可以帮助团队以更短的周期交付软件的方法,该方法确保了团队可以在任何时间发布出可靠的软件.该方法意在以更快速度更高频率进行软件的构建.测试和发布. 通过对生产环境中的应用程序进行 ...

  3. PPTP不使用远程网关访问公网设置

    使用PPTP拨号的时候默认使用PPTP远程网关访问公网,通过以下设置可以禁止远程网关访问公网 1,右下角选择网络图标右键-属性 2,选择网络IPv4属性,选择属性 3,点击高级选项 4,在远程网络上使 ...

  4. mini2440:通过JLink烧写BootLoader到Nor Flash

    开发板:友善之臂mini2440,64M Nand Flash操作系统:Win7电脑:笔记本Lenovo Y450连接器:由于我的笔记本没有并口,所有买了个J-Link和转接板软件:JLink驱动Se ...

  5. 反正切函数atan与atan2的区别

    atan 和 atan2 都是求反正切函数,如:有两个点 point(x1,y1), 和 point(x2,y2); 那么这两个点形成的斜率的角度计算方法分别是: float angle = atan ...

  6. HDU 1542 - Atlantis - [线段树+扫描线]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1542 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  7. ZOJ 3993 - Safest Buildings - [数学题]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3993 题意: 给出n幢建筑,每个都以一个点表示,给出点坐标. 有 ...

  8. element 表格元素 超链接

    1.在循环体中的事件绑定 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...

  9. CGI servlet Applet Scriptlet Scriptlet JSP data layer(数据层),business layer(业务层), presentation layer(表现层)

    https://en.wikipedia.org/wiki/Common_Gateway_Interface In computing, Common Gateway Interface (CGI) ...

  10. inaccessible

    $w = (object)array('key0'=>'a','key1'=>'b',0,1,2,0=>'0w',1=>'1w','11'=>'11str'); var_ ...