gpt4 book ai didi

python - 简单的密码程序

转载 作者:行者123 更新时间:2023-11-30 23:37:29 24 4
gpt4 key购买 nike

我正在尝试制作一个简单的小程序,告诉用户密码错误。
但是,当我希望程序取回他们输入的密码并说这是错误的时,它不会让我这么做。有人帮助我..

username = raw_input("Please enter your username: ")
password = raw_input("Please enter your password: ")
fail1 = raw_input("Your password is very insecure, make a new one: ")
print "Your password [password] is too weak!"

最佳答案

Python 不会神奇地格式化字符串,您需要显式地这样做:

print "Your password {} is too weak!".format(password)

参见Format string syntax了解 .format() 方法如何工作的更多信息。

或者,使用以下任意一种:

print "Your password", password, "is too weak!"
print "Your password %s is too weak!" % password
import string
template = string.Template("Your password ${password} is too weak!")
print template.substitute(password=password)

关于python - 简单的密码程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15509004/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com