-3
這就是它,問題在於它不會改變名詞和形容詞的值,並且打印0表示名詞,0表示形容詞,10表示打印數字的隨機數。任何人都可以修復我的ptyhon唯一密碼生成器?
from random import *
print("I get you password.")
i = 0
noun = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
adjective = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
addNoun = input("Would you like to add a noun? Type yes or no.")
if addNoun == "yes":
while addNoun == "yes" and i < 10:
noun[i] = input("Type a third person noun(You're first word). Use no spaces and try to use a mix of lower case and capital letters. ")
i = i + 1
addNoun = input("Would you like to add another noun? Type yes or no.")
elif addNoun == "no":
noun = ["He", "Mr.BossDude", "Dad", "Mom", "Acquaintance"]
else:
addNoun = input("I said type yes or no.")
if addNoun == "yes":
while addNoun == "yes" and i < 10:
noun[i] = input("Type a third person noun(You're first word). Use no spaces and try to use a mix of lower case and capital letters. ")
i+=1
addNoun = input("Would you like to add another noun? Type yes or no.")
else:
noun = ["He", "Mr.BossDude", "Dad", "Mom", "Acquaintance"]
addAdjective = input("Would you like to add an adjective or verb? Type yes or no.")
i = 0
if addAdjective == "yes":
while addAdjective == "yes" and i < 10:
adjective[i] = input("Type a verb or adjective(You're second word). Use no spaces and try to use a mix of lower case and capital letters. ")
i+=1
addAdjective = input("Would you like to add another noun? Type yes or no.")
elif addAdjective == "no":
adjective = ["IsGud", "Walks", "Sleeps", "Continues", "Falls", "SeesAll"]
else:
addAdjective = input("I said type yes or no.")
if addAdjective == "yes":
while addAdjective == "yes" and i < 10:
adjective[i] = input("Type a verb or adjective(You're second word). Use no spaces and try to use a mix of lower case and capital letters. ")
i+=1
addAdjective = input("Would you like to add another noun? Type yes or no.")
else:
adjective = ["IsGud", "Walks", "Sleeps", "Continues", "Falls", "SeesAll"]
number = randint(10, 99)
print("Your password is: " + str(choice(noun)) + str(choice(adjective)) + str(number))
我一直在試圖解決它,但我不明白爲什麼它不會再次設置列表。
嘗試把你的代碼分解成更小的單元,並確保在嘗試將更大的東西放在一起之前正確地工作。如果您有疑問,請閱讀文檔,並使用Python調試器「pdb」逐行檢查您的代碼,並嘗試仔細考慮邏輯錯誤的位置。否則,除非有一個可重現的問題,否則很難爲您提供幫助。 – Iguananaut
可能沒有多大幫助,但所有這些都可以重構爲一個循環,以便所有的代碼重複被刪除。當你發現自己一遍又一遍地輸入類似的代碼時,只有幾個不同之處,而且差別幾乎是數據,這是一個紅旗,你有一個想要寫入的函數。一旦代碼被減少,這將更容易調試。 – RobertB