Python
Python

Reputation: 23

Simple password program

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

Answers (4)

Martijn Pieters
Martijn Pieters

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

none
none

Reputation: 12117

print "Your password", password, "is to weak!"

Upvotes: 0

Fredrik Pihl
Fredrik Pihl

Reputation: 45670

Try:

print "Your password %s is to weak!" % password

Upvotes: 0

AlwaysBTryin
AlwaysBTryin

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

Related Questions