Generates a random numeric password of the specified length
Generates a random letter password of the specified length
Generates a mix of random numbers and letters of a specified length
#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 writes a class of password generators that require a class variable to count how many passwords are generated altogether. 4 methods Required, 1: Constructor Method 2 Instance Method 3 class Method 4 static method