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

  • SEARCH
  • Home
  • 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 8661023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:23:46+00:00 2026-06-12T16:23:46+00:00

I am writing a program in python that will take user birthday input and

  • 0

I am writing a program in python that will take user birthday input and output their western and chinese zodiac sign. Right now I am just trying to get the Chinese sign working. This is my code so far:

ZODIAC = [(1900, "Rat"), (1901, "Ox"), (1902, "Tiger"), (1903, "Rabbit"), (1904\
, "Dragon"), (1905, "Snake"), (1906, "Horse"), (1907, "Sheep"), (1908, "Monkey"\
), (1909, "Rooster"), (1910, "Dog"), (1911, "Pig")]

def getChineseZodiac(year):
    for i in ZODIAC:
        if (year - ZODIAC[i]) % 12 == 0:
            return ZODIAC[i]

year = input("Enter a year: ")
getChineseZodiac(year)

What I hope for this code to do is to run through each of those years in ZODIAC and find a match with modulus 0, and then return the string attached. But the error I get is TypeError: list indices must be integers, not tuple. How do I solve this?
Am I supposed to be using some other format for ZODIAC?

  • 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-12T16:23:47+00:00Added an answer on June 12, 2026 at 4:23 pm

    The exception you are getting is because of the way you are indexing the list. for i in ZODIAC sets i to a member of ZODIAC, not to an index. You can’t then use ZODIAC[i] and have it make sense. Instead, use i directly (in this case, by using i[0] and i in place of the two cases where you were using ZODIAC[i]). Or alternatively, if you do want to iterate over indexes, change your loop to use for i in range(len(ZODIAC)).

    However, the whole problem can be simplified. Since the signs in your list are in order, you can do just a single modulus calculation and use it as an index into the list, rather than iterating over the list values and testing each one:

    def getChineseZodiac(year):
        index = (year - ZODIAC[0][0]) % 12
        return ZODIAC[index]       # or ZODIAC[index][1], depending on what you want
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started learning Python... I am writing a simple program that will take
I am writing a basic program in Python that prompts the user to enter
I'm writing a Python program that will use Twisted to connect to a TCP
I am writing this little python program that will get new posts on the
I'm writing a python program that will spawn a subprocess to basically clone a
I am writing a program in Python that will act as a server and
Program Details: I am writing a program for python that will need to look
I'm writing a program that needs to take input from an XBox 360 controller.
I am writing a program in Python that will fit Gaussian and Lorentzian shapes
I'm writing a python program that uses scons to build an .exe and then

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.