0

Just a little project i'm working on to improve my knowledge. Curious as to why the program always returns failure, even if the captcha is correctly entered. I assume it has something to do with the results not being stored in memory?

import string
import random

def captcha_gen(size=7, chars=string.ascii_letters + string.digits):
    return ''.join(random.SystemRandom().choice(chars) for _ in range(size))

results = print(captcha_gen())

user_input = input("Please enter the captcha code as you see it: ")

if user_input == results:
    print("success")

elif user_input != results:
    print("failure")

else:
    print("error")

Thanks!

Joob Loob
  • 19
  • 3

1 Answers1

1

results = print(captcha_gen())

print() returns None - it is used to print stuff to the screen. In this case, it is grabbing the output of captcha_gen() and printing it to the screen.

All functions in Python return something - if they don't specify what they return, then it is an implicit None

You want

results = captcha_gen()

TemporalWolf
  • 7,727
  • 1
  • 30
  • 50