就是这样,问题是它不会改变名词和形容词的值,打印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))
我一直在试图解决它,但我不明白为什么它不会再次设置列表。你知道吗
原因是因为用10个零初始化名词和形容词列表,所以函数选择(名词)有90%的几率选择零。你知道吗
不要先初始化列表,然后再填充列表,不要声明列表,只需使用以下命令附加名词和形容词,例如:
除了数组处理不当之外,您还复制了数据和逻辑。您不需要更多的代码,只需要更少的简化:
相关问题 更多 >
编程相关推荐