就是这样,问题是它不会改变名词和形容词的值,并为名词打印0,为形容词打印0,为数字打印10到99之间的随机数。
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))
我一直在尝试修复它,但我不明白为什么它不会再次设置列表。
除了阵列处理不当,您还复制了数据和逻辑。你不需要更多的代码,你需要的更少——简化:
from random import randint, choice
print("I'll provide you a password.")
nouns = []
while not nouns:
addNoun = input("Would you like to add a noun? Type yes or no: ").lower()
if addNoun.startswith("y"):
while addNoun.startswith("y"):
nouns.append(input("Type a third person noun (you're first word). Use no spaces and use a mix of lower case and capital letters.\n"))
addNoun = input("Would you like to add another noun? Type yes or no: ").lower()
elif addNoun.startswith("n"):
nouns = ["He", "Mr.BossDude", "Dad", "Mom", "Acquaintance"]
else:
print('I said, "type yes or no."')
adjectives = []
while not adjectives:
addAdjective = input("Would you like to add an adjective or verb? Type yes or no: ").lower()
if addAdjective.startswith("y"):
while addAdjective.startswith("y"):
adjectives.append(input("Type a verb or adjective (you're second word). Use no spaces and use a mix of lower case and capital letters.\n"))
addAdjective = input("Would you like to add another noun? Type yes or no: ").lower()
elif addAdjective.startswith("n"):
adjectives = ["IsGud", "Walks", "Sleeps", "Continues", "Falls", "SeesAll"]
else:
print('I said, "type yes or no."')
number = randint(10, 99)
print("Your password is:", choice(nouns) + choice(adjectives) + str(number))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句