Case19. In the eastern calendar adopted a 60-year cycle, consisting of 12-year sub-cycles, denoted by the names of colors: green, red, yellow, white and black. In each sub-cycle, the years bear the names of animals: Rat, Ox, Tiger, Rabbit, Dragon, Snake, Horse, Sheep, Monkey, Rooster, Dog and Pig. By the year number, define its name, if 1984 is the beginning of the cycle: "the year of the Green Rat".
Solution in Python 3:
import random
title = {
1 : 'Rat',
2 : 'Ox',
3 : 'Tiger',
4 : 'Rabbit',
5 : 'Dragon',
6 : 'Snake',
7 : 'Horse',
8 : 'Sheep',
9 : 'Monkey',
10 : 'Rooster',
11 : 'Dog',
12 : 'Pig'
}
color = {
1 : 'Green',
2 : 'Red',
3 : 'Yellow',
4 : 'White',
5 : 'Black'
}
N = random.randrange(1900,2222)
N = 1932
#N = 1976
print("Year ",N)
year_name = 'Year of '
title_code = (N - 4) % 12 + 1
print("Title code: ", title_code)
print("Title: ", title[title_code])
color_code = (N - 4) % 10 + 1
color_code = int((color_code - 1) / 2) + 1
print("Color code: ", color_code)
print("Color: ", color[color_code])
year_name += color[color_code] + ' ' + title[title_code]
print(year_name)