0
私はこのコードを持っています。もし私がこれらの変数をすべて取り除くことができれば知りたいのですが、目的ごとに1つしか持たないでください。私のコードは、3つの異なるパスワード強度を持つパスワードジェネレータです。コードはこれがなくても動作しますが、設計上は小さくしたいと思っています。私はそれらの機能を作ろうとしましたが、うまくいきませんでした。私はおそらく明白な何かを欠いているでしょう:Python:ランダム変数をリフレッシュする方法
import time
import random
import string
ps = ""
name = ""
ans1 = ""
list_s = ["!","£","~","%","*","(","}","#",";","@","/",":","-"]
list_w = ["mouse","human","dog","tree","boom","thief","killer","dealer","feeler","man","woman","death"]
list_w2 =["help","yelp","empire","squire","lier","fryer","kitchen","bed","matress", "criminal","drug"]
rc1 = random.choice(string.ascii_lowercase)
rc2 = random.choice(string.ascii_lowercase)
rc3 = random.choice(string.ascii_lowercase)
rc4 = random.choice(string.ascii_lowercase)
rc5 = random.choice(string.ascii_uppercase)
rc6 = random.choice(string.ascii_uppercase)
rc7 = random.randrange(10)
rc8 = random.randrange(10)
rc9 = random.randrange(10)
rc10 = random.choice(list_s)
rc11 = random.choice(list_s)
rc12 = random.choice(list_w)
rc13 = random.choice(list_w2)
while name == "":
name = str(input("Welcome to password64, before we begin enter your name:"))
while ans1 == "":
ans1 = str(input("Have you used password64 before " + name + " ?"))
ans1 = ans1[0].lower()
if ans1 == "n":
print ("Thank you for trying password64 for the first time " + name + " !")
time.sleep(4)
print ("I will ask you the strength of the password you want, there will be three options: Strong, Medium or Weak")
time.sleep(6)
print ("A strong password is a mix of random numbers, letters and symbols")
time.sleep(3)
print ("A medium password will be a couple of words with random numbers and symbols")
time.sleep(3)
print ("A weak password will be a couple of words with a number")
elif ans1 == "y":
print ("Thank you for reusing password64 " + name + " !")
time.sleep(2)
print ("Let's get straight on with it then")
while ps == "":
ps = str(input("Do you with to generate a strong, medium or weak password?"))
ps = ps[0].lower()
if ps == "s":
a = [rc1 , rc2, rc3, rc4, rc5, rc6, rc7, rc8, rc9, rc10, rc11]
elif ps == "m":
a = [rc12, rc13, rc7, rc8, rc10, rc11]
elif ps == "w":
a = [rc12, rc13, rc7]
else:
print ("You did not enter a valid password strength")
exit()
random.shuffle(a,random.random)
print ("Your password is generating....")
for i in range(0,len(a)):
time.sleep(1)
print (a[i], end="")
print ("")
print ("Your password is ready to be used " + name + ". Thank you for using password64")
'r1'を' r6'に 'r6'を置き換えます:' r = lambda:random.choice(string.ascii_lowercase) 'これは、あなたが呼び出すたびにランダムな文字を生成するか、'ランダムを使用します。パスワードの作成時に直接選択(...) ' –