【问题标题】:Random Key Generator In Python 3 [closed]Python 3中的随机密钥生成器[关闭]
【发布时间】:2021-07-27 18:15:22
【问题描述】:

我制作了一个随机密钥生成器,它甚至可以用来为你创建一个新密码。

import random
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"
while 1:
    key_len = int(input("What length would you like your key to be?: "))
    key_count = int(input("How many keys would you like?: "))
    for x in range(0,key_count):
        key = ""
        for x in range(0,key_len):
            key_char = random.choice(chars)
            key = key + key_char
        print("Here's your key: ",key)

输出:

What length would you like your key to be?: 4
How many keys would you like?: 1
Here's your key: 1337
What length would you like your key to be?: 

【问题讨论】:

  • 你应该包含你得到的错误:SyntaxError: invalid syntax for x in range(0,key_len)
  • 我忘了。

标签: python python-3.x random generator


【解决方案1】:
for x in range(0,key_len)

你忘了用冒号结尾。在我把冒号代码为我工作之后

for x in range(0,key_len):

【讨论】:

  • 我可能不小心删除了冒号,当我尝试优化代码时。但否则感谢您指出这一点。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-10
  • 2015-09-27
  • 1970-01-01
  • 2016-07-17
  • 1970-01-01
相关资源
最近更新 更多