1

I'm trying to make a simple Python function that prints two things;

  1. What day of the week it currently is.
  2. How many days it is until Christmas.

I don't get any errors when I run this, however nothing prints either. In fact nothing at all happens when its run.

I've checked and I've installed the datetime module correctly (I think).

Screenshot of cmd prompt confirmation

I'm not really sure what I'm doing wrong so any guidance would be helpful.

As you can probably guess, I'm relatively new to Python/stackoverflow.

Thanks.

Edit: I stupidly named the file itself datetime.py because yes I am that stupid.

from datetime import *

def day_of_week():
    """ Python function to return a specified day of the week"""
    today_date = date.today()

    thisYear = today_date.year
    xmas = date(thisYear,12,25)

    day_of_week =("Mon","Tue","Wed","Thu","Fri","Sat","Sun")[today.weekday]
    print("It's a %s." % (day_of_week))

    days_to_xmas = (xmas - today_date).days
    print("There are %i days to xmas!" & days_to_xmas)
Ian Murray
  • 87
  • 8
  • 1
    Try .today().weekday() this answer may help your problem: [https://stackoverflow.com/questions/9847213/how-do-i-get-the-day-of-week-given-a-date][1] – Christian Mahardhika Jan 28 '20 at 18:19
  • 1
    You define the function to later call it, or use it. Simply add `day_of_week()` in the last line and run the full script again, It should print something or generate an error if there's something wrong with it. – Celius Stingher Jan 28 '20 at 18:19
  • Thanks for all your contributions. My issue was that I stupidly named, the python script "datetime.py" – Ian Murray Jan 28 '20 at 18:40

1 Answers1

1

Try calling the function in the script , you defined the function but never executed it.

day_of_week()

manoj yadav
  • 347
  • 2
  • 7