是否可以使用任何语句再次运行代码?
import random
import sys
print("Password Generator")
print("* Attention: - You may not generate a password with more than 70 characters\n"
" - You may not enter letters")
characters = "abcdefghijklmnopqrstuvwxyz" \
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*"
pass_length = input("Enter your password length: ")
在这里,我只想确保用户输入是数字而不是字母的信息!
if pass_length.isnumeric() is False:
sys.exit("Natural numbers only!")
是否有一个语句可以在激活上面的“ if”语句之后自动运行脚本?
def password_gen_start():
password = "".join(random.sample(characters, int(pass_length)))
print("Your password has been generated: " + format(password))
if int(pass_length) >= 71 and pass_length.isnumeric() is True:
sys.exit("Password cannot be longer than 70 characters!")
if int(pass_length) < 71 and pass_length.isnumeric() is True:
password_gen_start()
import random
import sys
print("Password Generator")
print("* Attention: - You may not generate a password with more than 70 characters\n"
" - You may not enter letters")
characters = "abcdefghijklmnopqrstuvwxyz" \
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*"
pass_length = input("Enter your password length: ")
Here I just want to make sure the information that the user's input are numbers, not letters!
if pass_length.isnumeric() is False:
sys.exit("Natural numbers only!")
Is there a statement that can automatically run the script again after the "if" statement above is activated?
def password_gen_start():
password = "".join(random.sample(characters, int(pass_length)))
print("Your password has been generated: " + format(password))
if int(pass_length) >= 71 and pass_length.isnumeric() is True:
sys.exit("Password cannot be longer than 70 characters!")
if int(pass_length) < 71 and pass_length.isnumeric() is True:
password_gen_start()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需要在一段时间内将其放置:
You just have to put it in a while loop :
谢谢Nicolas,现在我终于可以完成我的代码:
Thank you Nicolas, now I can finally finish my code: