これは、名詞と形容詞の値を変更せず、名詞の場合は0、形容詞の場合は0、数字の場合は10と99の間の乱数を出力するという問題です。誰も私の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'を使って一度に1行ずつコードを実行し、ロジックが間違っている場所を注意深く検討してみてください。それ以外の場合、再現性のある問題が1つしかないかぎり、あなたを助けるのは難しいです。 – Iguananaut
おそらくそれほど助けにはなりませんが、このすべてをループにリファクタリングしてすべてのコードの繰り返しを削除することができます。わずかな違いがあり、その違いがかなりのデータであるところに何度も同じようなコードを繰り返し入力していると、これは書かれたい機能を持つ赤旗です。一度コードを減らすと、デバッグがはるかに簡単になります。 – RobertB