如何使程序要求用户输入长度并使用输入来制作用户想要的密码
#random password generator
import random
unified_code = "awertyuiosqpdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890!@#$%^&*()_+"
passlength1=input("how long should your password be")
pass_length2=input("how long should your password be")
def generatrandompaassword():
length = random.randint(passlength1,pass_length2 )
password = ""
for index in range(length):
randomCharacter = random.choice(unified_code)
password = password + randomCharacter
return password
passworder = generatrandompaassword()
print(passworder)
print("This is your new password")
这不会让我出于某种原因发布评论
这是几天前我启动Python的代码IV,所以我很陌生
fist fist,我尝试放置一个可变而且,询问用户输入并将输入插入程序并使用它来查找应为此获得帮助的时间的长度吗?
#random password generator
import random
unified_code = "awertyuiosqpdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890!@#$%^&*()_+"
passlength1=input("how long should your password be")
pass_length2=input("how long should your password be")
def generatrandompaassword():
length = random.randint(passlength1,pass_length2 )
password = ""
for index in range(length):
randomCharacter = random.choice(unified_code)
password = password + randomCharacter
return password
passworder = generatrandompaassword()
print(passworder)
print("This is your new password")
this won't let me post for some reason what is a comment
this is the code iv made I started python a couple of days ago so I'm pretty new to it
fist I tried putting one-variable and than asking the user for the input and inserting the input into the program and using that to find the length of how long the password should be can get help with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我重新编写了您的代码。
您可以阅读评论以查看正在发生的事情。
本质上,我们有一个字符列表,这些字符将在密码中使用。
然后,我们向用户询问其密码的长度,然后将其转换为一个数字。
之后,我们循环浏览长度,并在密码中添加一个随机字符。
I re-wrote your code.
You can read the comments to see what is happening.
Essentially, we have a list of characters that will be used in the password.
We then ask the user for the length of their password, and convert it to a number.
After, we loop through the length and add a random character to the password.
代码 - 您的代码需要进行细微更改
您从用户收到的输入是
str
类型,因此您需要将其转换为int
数据类型。输出
建议:
_
或驼峰命名法。pass_length1
和randomCharacter
有两种样式。generate_random_password
比generatrandompaassword
=
前后留出一些空间。Code - Your code needed minor changes
The input your receive from the user is of type
str
, so you need to convert it intoint
data type.Output
Suggestions:
_
or camelCasing.pass_length1
andrandomCharacter
are of two styles.generate_random_password
thangeneratrandompaassword
=
before and after.在此处输入图像描述
这是我解决此问题的方法,我无法从上面获得正确的输出代码所以测试我的方式,祝你好运
enter image description here
It is my way to solve this , I could not get right output from above codes so test my way, good luck