Chinese New Year Coding Challenge

Chinese New Year (新年) aka Spring Festival (春节), is one of the most important festivals in Chinese culture. It has been celebrated in China for thousands of years. People celebrate by decorating their interior in red using red couplets of Chinese poetry, lanterns and colourful flowers. The festival is also the opportunity for Chinese people around the world to prepare and enjoy a range of traditional food dishes and to celebrate by watching traditional dragons and lions dances.

Chinese Zodiac Signs

The Chinese New Year is based on the Lunar calendar and typically falls at the end of January or in February depending on the Moon cycle. Every year is associated with an animal corresponding to a Chinese Zodiac sign. There is a 12-year cycle with twelve zodiac signs in the following order:

Animal/Zodiac Sign Years
Dragon … 2000, 2012, 2024 …
Snake … 2001, 2013, 2025 …
Horse … 2002, 2014, 2026 …
Ram (Goat) … 2003, 2015, 2027 …
Monkey … 2004, 2016, 2028 …
Rooster … 2005, 2017, 2029 …
Dog … 2006, 2018, 2030 …
Pig … 2007, 2019, 2031 …
Rat … 2008, 2020, 2032 …
Ox … 2009, 2021, 2033 …
Tiger … 2010, 2022, 2034 …
Rabbit … 2011, 2023, 2035 …

So this year we will celebrate Chinese New Year on January 29th 2025 and the Chinese Zodiac sign / animal for 2025 is the Snake! Maybe a sign that you could dedicate this year to boosting your coding skills using Python 😉

Coding Challenge

For this challenge, you are going to write a Python program that will ask the user to enter the year of their date of birth. Your program will then inform the user of their Chinese Zodiac sign matching their date of birth.

Python Code

Complete the code below to solve this challenge.

Test Plan:

Complete the folowing test plan to check if your code is giving you the correct zodiac signs for he following years (using both past and future years):

Test # Input Values Expected Output Actual Output
#1 Year: 2007 Pig
#2 Year: 2021 Ox
#3 Year: 1998 Tiger
#4 Year: 1912 Rat
#5 Year: 1789 Rooster
#6 Year: 2050 Horse
#7 Year: 2100 Monkey

Extension Task 1:

With the year matching your date of Birth you can also work out what is your Chinese Zodiac element.

To do so you wil need to check the the last digit of your birth year. if this last digit is:

  • 0 or 1: Your element is Metal
  • 2 or 3: Your element is Water
  • 4 or 5: Your element is Wood
  • 6 or 7: Your element is Fire
  • 8 or 9: Your element is Earth

Your task is to tweak your Python code so that when the user enters a date, your program outputs both the Chinese Zodiac sign and the Chinese Zodiac element corresponding to the given year.

Extension Task 2:

Each Zodiac sign has specific attributes which can be used to describe the year to come.

We have stored these attributes using a dictionary:

animals = {"Dragon":"Charismatic, powerful, and ambitious, the Dragon is a symbol of strength and good fortune.",
           "Snake":"Wise, intuitive, and elegant, the Snake is calm and strategic, with a deep understanding of the world.",
           "Horse":"Energetic, free-spirited, and optimistic, the Horse loves adventure and pursues goals with enthusiasm.",
           "Ram":"Creative, gentle, and empathetic, the Goat seeks beauty and tranquillity, often expressing artistic talents.",
           "Monkey":"Intelligent, playful, and clever, the Monkey is resourceful and loves solving problems with wit and charm.",
           "Rooster":"Confident, honest, and hardworking, the Rooster is practical, ambitious, and detail-oriented.",
           "Dog":"Loyal, trustworthy, and protective, the Dog is compassionate and always stands up for what’s right.",
           "Pig":"Generous, kind-hearted, and sincere, the Pig is known for its honesty, hard work, and love of comfort.",
           "Rat":"Intelligent, resourceful, and quick-witted, the Rat excels in finding opportunities and achieving success.",
           "Ox":"Strong, determined, and reliable, the Ox is known for its hardworking nature and steadfast loyalty.",
           "Tiger":"Bold, adventurous, and confident, the Tiger is a natural leader who thrives on challenges.",
           "Rabbit":"Gentle, compassionate, and creative, the Rabbit seeks peace and harmony in its surroundings."
}

Your task is to tweak your code to display the corresponding description of the zodiac sign for the given year.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 5

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!