I am trying to create a function in python which will display the date. So I can see the program run, I have set one day to five seconds, so every five seconds it will become the next 'day' and it will print the date.
I know there is already an in-build function for displaying a date, however I am very new to python and I am trying to improve my skills (so excuse my poor coding.)
I have set the starting date to the first of January, 2000.
Here is my code:
import timedef showDate():year = 00month = 1day = 1oneDay = 5longMonths = [1, 3, 5, 7, 8, 10, 12]shortMonths = [4, 6, 9, 11]while True:time.sleep(1)oneDay = oneDay - 1if oneDay == 0:if month in longMonths:if day > 31:day = day + 1else:month = month + 1day = 0if month == 2:if day > 28:day = day + 1else:month = month + 1day = 0if month in shortMonths:if day > 30:day = day + 1else:month = month + 1day = 0if day == 31 and month == 12:year = year + 1print(str(day) + '/' + str(month) + '/' + str(year))oneDay = 5showDate()
However, when I try to run the program this is the output I get this:
>>>
0/3/0
0/5/0
0/7/0
0/8/0
0/10/0
0/12/0
0/13/0
0/13/0
0/13/0
I don't know why this is happening, could someone please suggest a solution?