M
M
mirindanda2021-12-15 21:17:44
Python
mirindanda, 2021-12-15 21:17:44

Why does the function return None?

from datetime import date, timedelta
import os 
os.system('cls')

def date():
    s = input("Write 1 for today, 2 for yesterday and 3 for random date: ")
     
    if s == 1:
        last_date = (date.today())
        link_today = "https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY&date=" + str(last_date)
        return link_today
    elif s == 2:
        yesterday = print(date.today() + timedelta(days=-1)
        return yesterday
date()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-12-15
@mirindanda

First, input returns a string, which obviously cannot equal a number. Secondly, there are no alternative conditions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question