i tried to make function, where i can choose the date. Like today, yesterday or random day from 2000-01-01
Here is my try, but cant and dont understand a little bit how to make it right. Thank you!
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:
link_today = "https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY&date=" + str(date.today())
return link_today
elif s == 2:
yesterday = date.today() + timedelta(days=-1)
print(yesterday)
return yesterday
date()
date
fromdatetime
. Don't call your functiondate
– not_speshalinput()
returnsstr
and you compares
withint
value (1 or 2) - they will never be equal. – buranget_date
would be better. And, by the way,os.system('cls')
is not a good practice. You don't know whether the user had something on their screen they wanted to keep for later. Plus, it's Windows-only. And remember thatinput
returns a string, not an integer. You needif s == '1':
– Tim Robertsinput
will be a string, but you are comparing it to integers. I would recommend castings
toint
or changing yourif
statements to compare using strings like so:if s == '1':
– VoidTwo