NameError: name 'm' is not defined cannot be resolved

Asked 2 years ago, Updated 2 years ago, 19 views

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)

python

2022-09-30 19:29

1 Answers

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:

    Before running
  • 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.
whileTry reviewing the actions in the loop


2022-09-30 19:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.