Python 简单密码程序
我正在尝试制作一个简单的小程序,告诉用户密码有误。Python 简单密码程序,python,Python,我正在尝试制作一个简单的小程序,告诉用户密码有误。 但是,当我想让程序带回他们输入的密码,并说它是错误的,它不会让我。谁来帮帮我 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 "Yo
但是,当我想让程序带回他们输入的密码,并说它是错误的,它不会让我。谁来帮帮我
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!"
如果要在另一个字符串中显示字符串,则需要使用%。例如:
print "Your password [%s] is too weak" % password
尝试:
Python不会神奇地格式化字符串,您需要显式地这样做: 有关
.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)
你怎么会说“它不会让你”呢?你有没有更多的代码不给我们看?什么意思它不让你看?它会出错吗?出于对各地语法极客的热爱,请确保在实现之前将其更改为“太弱!”(带有两个o)。(我知道这就是op的问题所在,@MartijnPieters)好了,至少在我的回答中,语法平衡得到了恢复。
print "Your password {} is too weak!".format(password)
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)
print "Your password", password, "is to weak!"