I want to create a program that returns all Sunday dates of the year with a list in string YYYY-MM-DD format when I pass the year as an argument.
There is an error on all_sunday(y,m,d) at the bottom
y=int(input("What year?:"))
import datetime
default_Sunday(y,m,d):
dt = datetime.datetime(y,1,1)
s=dt.weekday()
a = 6-s
x=dt+datetime.timedelta(days=a)
k = x.year
z = x
while True:
print(z)
z=x+datetime.timedelta(days=7)
c=z.year
if k<c:
break
all_sunday(y,m,d)
where y
is the first line of y=int(input("What year is it?):US>")
has declaration and input values, but m
(and d
) have not been declared or configured anywhere.
This means that m
is not defined as per the message, so it is an error.
By the way, defall_sunday(y,m,d): It is declared as a provisional argument in the
function, but it is not necessary as it is because nothing is used in the processing in the function.
Possible actions include:
all_sunday(y,m,d)
, make dummy variable declarations and value settings such as m=1
and d=1
.all_sunday(y,m,d)
and def all_sunday(y,m,d): Delete ,m,d
as they do not need both
.Then there is a bug in the all_sunday()
function, and it does not end in an infinite loop.
while
Try reviewing the actions in the loop
© 2024 OneMinuteCode. All rights reserved.