谁能修复我的 Python 唯一密码生成器?

雷电威特

就是这样,问题是它不会改变名词和形容词的值,并为名词打印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))

我一直在尝试修复它,但我不明白为什么它不会再次设置列表。

cdlane

除了阵列处理不当,您还复制了数据和逻辑。你不需要更多的代码,你需要的更少——简化:

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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何将一个元组的Python生成器拆分为2个单独的生成器?

来自分类Dev

python,生成器迭代一个或多个项目

来自分类Dev

Python v3(随机密码生成器)

来自分类Dev

Python报表生成器

来自分类Dev

Python:生成器失败

来自分类Dev

并发的python生成器

来自分类Dev

Python assertEquals生成器

来自分类Dev

在python 3.4中增强我的代码(Wordslist生成器)

来自分类Dev

Python:递归生成器

来自分类Dev

列出的Python生成器

来自分类Dev

Python生成器的缺点?

来自分类Dev

Python内联生成器

来自分类Dev

如何在python中修复rondom生成器?每当我运行CNN时,都会得到不同的结果

来自分类Dev

我在python 3中将生成器与输入函数一起使用时遇到问题

来自分类Dev

Python生成器使我感到困惑

来自分类Dev

任何人都可以在python的密码生成器中修复逻辑问题

来自分类Dev

为什么我无法在网站上为密码生成器生成密码?

来自分类Dev

Python:递归生成器

来自分类Dev

Python生成器返回最后一个项目

来自分类Dev

素数生成器-Python

来自分类Dev

Python assertEquals生成器

来自分类Dev

Python GUI生成器

来自分类Dev

我的Python函数中有一个生成器;如何返回修改后的列表?

来自分类Dev

Python生成器并减少

来自分类Dev

密码生成器 Python 列表

来自分类Dev

我想创建一个生成器来生成任意两个输入生成器的交集

来自分类Dev

我怎么能洗牌 python 无限生成器

来自分类Dev

python 生成器不能按我的预期工作

来自分类Dev

VS 中的随机密码生成器 - Python 3