w3resource

Python Exercise: Display sign of the Chinese Zodiac for given year

Python Conditional: Exercise - 39 with Solution

Write a Python program to display the sign of the Chinese Zodiac for given year in which you were born.

Sample Solution:

Python Code:

year = int(input("Input your birth year: "))
if (year - 2000) % 12 == 0:
    sign = 'Dragon'
elif (year - 2000) % 12 == 1:
    sign = 'Snake'
elif (year - 2000) % 12 == 2:
    sign = 'Horse'
elif (year - 2000) % 12 == 3:
    sign = 'sheep'
elif (year - 2000) % 12 == 4:
    sign = 'Monkey'
elif (year - 2000) % 12 == 5:
    sign = 'Rooster'
elif (year - 2000) % 12 == 6:
    sign = 'Dog'
elif (year - 2000) % 12 == 7:
    sign = 'Pig'
elif (year - 2000) % 12 == 8:
    sign = 'Rat'
elif (year - 2000) % 12 == 9:
    sign = 'Ox'
elif (year - 2000) % 12 == 10:
    sign = 'Tiger'
else:
    sign = 'Hare'

print("Your Zodiac sign :",sign)

Sample Output:

Input your birth year: 1784                                                                                   
Your Zodiac sign : Dragon  

Flowchart :

Flowchart: Display sign of the Chinese Zodiac for given year

Visualize Python code execution:

The following tool visualize what the computer is doing step-by-step as it executes the said program:

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to display astrological sign for given date of birth.
Next: Write a Python program to find the median of three values.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

Trenary operator:

>>> "Python ROCK" if True else " I AM GRUMPY"
"Python ROCK"