Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions problem_set/Q2_Chinese_Zodiac.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,31 @@

# write a function that takes the year as the input and produces the Zodiac for that year
# output should be in the format "2000 is the year of the Fire Rat"
chinese_dict= {
'animals': ["Rat","Ox","Tiger","Rabbit","Dragon","Snake","Horse","Goat","Monkey","Rooster","Dog","Pig"],
'elements': ["Fire", "Earth", "Metal", "Water", "Wood"]
}
year=2000
def chinese_new_year(x):
"""
Takes a inputted year, and output what Chinese Zodiac is for that year
"""
x = int(x)
# Initialized for 2024 and cycles through the total 60 states the Zodiac may be.
## It is aligned with the index numbers of the list
year = (x-2024) % 60

result=[]
for element in chinese_dict["elements"]:
for animal in chinese_dict["animals"]:
order = f"{element} {animal}"
result.append(order)
Zodiac = result[year]
if x<2024:
Messege = f"{x} was the year of the {Zodiac}"
else:
Messege = f"{x} is the year of the {Zodiac}"
return Messege

Zodiac = chinese_new_year(input("Input a year to determine it's associated Zodiac: "))
print(Zodiac)