Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9226731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:54:00+00:00 2026-06-18T04:54:00+00:00

I’m writing a script which calculates the date of Easter for years 1900 –

  • 0

I’m writing a script which calculates the date of Easter for years 1900 – 2099.
The thing is that for 4 certain years (1954, 1981, 2049, and 2076) the formula differs a little bet (namely, the date is off 7 days).

def main():
    print "Computes the date of Easter for years 1900-2099.\n"

    year = input("The year: ")

    if year >= 1900 and year <= 2099:
        if year != 2049 != 2076 !=1981 != 1954:
            a = year%19
            b = year%4 
            c = year%7
            d = (19*a+24)%30
            e = (2*b+4*c+6*d+5)%7
            date = 22 + d + e     # March 22 is the starting date
            if date <= 31:
                print "The date of Easter is March", date
            else:
                print "The date of Easter is April", date - 31
        else: 
            if date <= 31:
                print "The date of Easter is March", date - 7 
            else:
                print "The date of Easter is April", date - 31 - 7
    else:
        print "The year is out of range."   


main()

Exerything is working well but the 4 years computation.

I’m getting the:
if date <= 31:
UnboundLocalError: local variable 'date' referenced before assignment
whenever I’m entering any of the 4 years as input.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:54:01+00:00Added an answer on June 18, 2026 at 4:54 am

    You cannot chain a expression like that; chain the tests using and operators or use a not in expression instead:

    # and operators
    if year != 2049 and year != 2076 and year != 1981 and year != 1954:
    
    # not in expression
    if year not in (2049, 2076, 1981, 1954):
    

    The expression year != 2049 != 2076 !=1981 != 1954 means something different, it is interpreted as (((year != 2049) != 2076) !=1981) != 1954 instead; the first test is either True or False, and neither of those two values will ever be equal to any of the other numbers and that branch will always evaluate to False.

    You will still get the UnboundLocalError for date though, since your else branch refers to date but it is never set in that branch. When the else branch executes, all Python sees is:

    def main():
        print "Computes the date of Easter for years 1900-2099.\n"
    
        year = input("The year: ")
    
        if year >= 1900 and year <= 2099:
            if False:    
                # skipped
            else: 
                if date <= 31:
                    print "The date of Easter is March", date - 7 
                else:
                    print "The date of Easter is April", date - 31 - 7
    

    and date is never assigned a value in that case. You need to calculate date separately in that branch still, or move the calculation of the date value out of the if statement altogether; I am not familiar with the calculation of Easter so I don’t know what you need to do in this case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I am writing an app for my school newspaper, which is run completely online
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am using JSon response to parse title,date content and thumbnail images and place
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.