Advertisement
Talithacelin

Code Generator

Aug 26th, 2022 (edited)
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.90 KB | None | 0 0
  1. #CODE GENERATOR
  2. #4th - start endofaugust , three days+-
  3. import random
  4. import secrets
  5. import string
  6. import sys
  7.  
  8. def random_alnum(letter_count, digit_count):  
  9.     str1 = ''.join((random.choice(string.ascii_letters) for x in range(letter_count)))  
  10.     str1 += ''.join((random.choice(string.digits) for x in range(digit_count)))  
  11.  
  12.     sam_list = list(str1)
  13.     random.shuffle(sam_list)
  14.     final_string = ''.join(sam_list)  
  15.     return final_string  
  16.  
  17. def random_alnpu(letter_count, digit_count, punc_count):
  18.     str1 = ''.join((random.choice(string.ascii_letters) for x in range(letter_count)))  
  19.     str1 += ''.join((random.choice(string.digits) for x in range(digit_count)))  
  20.     str1 += ''.join((random.choice(string.punctuation) for x in range(punc_count)))
  21.  
  22.     sam_list = list(str1)
  23.     random.shuffle(sam_list)
  24.     final_string = ''.join(sam_list)  
  25.     return final_string  
  26.  
  27.  
  28. while True:
  29.     print("-------------------")
  30.     print("Code Generator (or Password Generator?)")
  31.     print("-------------------")
  32.  
  33.     code = ["1. Random Letters" ,"2. Random Numbers", "3. Random Numbers + Letters" , "4. Random Numbers + Letters + Punctuations"]
  34.     for options in code:
  35.         print(options)
  36.  
  37.     code = input("Please type the number of one of the option above! ")
  38.     cd = int(code)
  39.  
  40.     if code == "1" :
  41.         print()
  42.         rep = str(input("May have repeatable characters? : "))
  43.         if rep == "yes" or rep == "Yes":
  44.             alpha=int(input("How many letters? : "))
  45.             rdmalpha = ''.join(secrets.choice(string.ascii_letters) for x in range(alpha))  
  46.             print ("Here's your code: " , str(rdmalpha))
  47.  
  48.         else :
  49.             def norepeat(length):  
  50.                 letters = string.ascii_lowercase
  51.                 result1 = ''.join((random.sample(letters, length)))  
  52.                 print ("Here's your code: " , result1)
  53.             num1=int(input("How many letters? : "))
  54.             norepeat(num1)
  55.  
  56.     elif int(code == "2") :
  57.         print()
  58.         number=int(input("How many numbers? : "))
  59.         rdmnum = ''.join(secrets.choice(string.digits) for x in range(number))
  60.         print("Here's your code: " , str(rdmnum))
  61.        
  62.     elif int(code == "3") :
  63.         print()
  64.         let = int(input("How many letters? : "))
  65.         num = int(input("How many numbers? : "))
  66.         print("Here's your code: " , random_alnum(let, num))
  67.  
  68.     elif int(code == "4") :
  69.         print()
  70.         let1 = int(input("How many letters? : "))
  71.         num1 = int(input("How many numbers? : "))
  72.         punc = int(input("How many punctuations? : "))
  73.         print("Here's your code: " , random_alnpu(let1, num1, punc))
  74.    
  75.     print()
  76.     again= input("Would you like to try again? : ")
  77.     if again == "Yes" or again == "yes":
  78.         continue
  79.     else :
  80.         print("Thanks for using the code generator!")
  81.         sys.exit()
  82.  
  83. #Talice ~
  84.    
  85.    
  86.  
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement