-1
import whois ; import time ; from datetime import datetime ; import requests ; import re

date = False
points = 0

class bcolors:  #  just adding colors, ignore this
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'


def date_c():
    if date:
        print(f'{bcolors.OKGREEN}{td}Y{bcolors.ENDC}')
    else:
        print(f'{bcolors.FAIL}Less than a year{bcolors.ENDC}')

user_input = input('Site Link: ')

domain = whois.whois(user_input)
name = domain.domain_name[0]

d1 = domain.creation_date[0].strftime('%Y')
d2 = datetime.today().strftime('%Y')
td = int(d2) - int(d1)

if td >= 1:
    points += 2
    date = True

print(f'''
{'-' * (len(name) + 8)}
DOMAIN: {name}
| Age: {date_c()}  # This is None, and the value is displayed outside from here
| Secure:
| Status:
| Emails:
| Address:
| City:
| Recently Updated:
{'-' * (len(name) + 8)}
''')

I am getting the age of google, then if the age(in years) is >= 1 then date = True, and if date = true, in the printf statement display it, but the value is outside and date_c is somehow None. Any help is appreciated!

Iso
  • 93
  • 2
  • 5
  • Does this answer your question? [How is returning the output of a function different from printing it?](https://stackoverflow.com/questions/750136/how-is-returning-the-output-of-a-function-different-from-printing-it) – 001 May 19 '21 at 19:25

1 Answers1

-1

the value is outside and date_c is somehow None

This function returns None because there's no explicit return statement:

def date_c():
    if date:
        print(f'{bcolors.OKGREEN}{td}Y{bcolors.ENDC}')
    else:
        print(f'{bcolors.FAIL}Less than a year{bcolors.ENDC}')

"The value is outside" because Python will call date_c in order to construct the resulting f-string, but date_c will print something to the terminal via its print calls and return None, which will be incorporated into the f-string. Only then the resulting string will be printed, and now there are two outputs.

You should probably return the strings from date_c:

def date_c():
    if date:
        return f'{bcolors.OKGREEN}{td}Y{bcolors.ENDC}'
    else:
        return f'{bcolors.FAIL}Less than a year{bcolors.ENDC}'
ForceBru
  • 43,482
  • 10
  • 63
  • 98