1

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

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!"
4

4 回答 4

3

Python 不会神奇地格式化字符串,你需要明确地这样做:

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

有关该方法如何工作的更多信息,请参阅格式化字符串语法。.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)
于 2013-03-19T19:47:21.150 回答
0

如果要在另一个字符串中显示字符串,则需要使用 %。例如:

print "Your password [%s] is too weak" % password
于 2013-03-19T19:47:14.570 回答
0

尝试:

print "Your password %s is to weak!" % password
于 2013-03-19T19:47:19.820 回答
0
print "Your password", password, "is to weak!"
于 2013-03-19T19:47:52.097 回答