Reputation: 23
I'm trying to make a simple little program that tells the user that there password is wrong.
But when I want the program to bring back the password they entered and say that it's wrong it won't let me. Somebody help me..
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!"
Upvotes: 1
Views: 1209
Reputation: 1124718
Python does not magically format strings, you need to do that explicitly:
print "Your password {} is too weak!".format(password)
See Format string syntax for more information how the .format()
method works.
Alternatively, use any of:
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)
Upvotes: 3
Reputation: 1964
If you want to display a string inside another one, you need to use %. For example:
print "Your password [%s] is too weak" % password
Upvotes: 0