0

sorry for the question title, I don't know how to word it. I coded a program that guessed your password by randomly generating passwords until it gets a match. you could only change the password by editing the code, I wanted to upgrade it and make it so you can type the password in the console and it guesses it but when I tried it had a bug. This is what happened: this is my code

letter=("a""b""c""1""2""3")
import random
print ("Please type a 6 character password with a, b, c, 1, 2, 3, you may use characters more than once.")
password = input
spam=(random.choice(letter)+""+random.choice(letter)+""+random.choice(letter)+""+random.choice(letter)+random.choice(letter)+""+random.choice(letter))
found = spam == password
if not found:
  print(spam)
elif found:
 print ("I found your password: " + spam)

but when I start the code this is what happens

Please type a 6 character password with a, b, c, 1, 2, 3, you may use characters more than once.
c1aca2

instead of just showing the instructions it shows a password combination. another issue it that when I type in the password and click enter I get a syntax error

2 Answers2

0

Change this line

password = input

to

password = input()

If you don't include the parentheses you are assigning password to the function input. Instead you have to call the function input() for password to be assigned of what's returned by input().

Sandsten
  • 727
  • 3
  • 16
0

You can use the following function.

import random

def guessPassword():
    password = input("Please type a 6 character password with a, b, c, 1, 2, 3, you may use characters more than once.")
    spam = (random.choice(letter)+""+random.choice(letter)+""+random.choice(letter)+""+random.choice(letter)+random.choice(letter)+""+random.choice(letter))
    i = 1   
    while(spam != password):
        spam = (random.choice(letter)+""+random.choice(letter)+""+random.choice(letter)+""+random.choice(letter)+random.choice(letter)+""+random.choice(letter))    
        i += 1
    print("I found your password at %d times" % (i))
    print("Your password is: %s" % (spam))