SoFunction
Updated on 2024-11-20

Example of writing python to determine zodiac sign based on year

concern

Write a program that when a user enters their year of birth, the following Python program calculates and outputs their phases based on the Chinese Zodiac dating method.

methodologies

In the Chinese Zodiac dating system, there are 12 different genera in a year. We assign the remainder to the variable 'X' to get the corresponding genus. A conditional statement (if-elif-else statement) is used to determine the user's genus. If the value of is 0, it means that the year is the year of monkey. If the value is 1, the year is the Year of the Rooster. And so on. If the value is anything other than 0-11, then the final else statement will output "Your birth year is Sheep". The final output is the user's genus.

year = int(input("Please enter the year of birth:"))
X = year % 12
if X == 0:
   print("You're a monkey.")
elif X == 1:
   print("Your sign is chicken.")
elif X== 2:
   print("You're a dog.")
elif X == 3:
   print("You're a pig.")
elif X == 4:
   print("You're a rat.")
elif X == 5:
   print("You're an ox.")
elif X == 6:
   print("You're a tiger.")
elif X == 7:
   print("You're a rabbit.")
elif X == 8:
   print("Your genus is the dragon.")
elif X == 9:
   print("You're a snake.")
elif X == 10:
   print("You're a horse.")
else:
   print("You're a sheep.")

concluding remarks

This Python code implements a simple phases determination program, which calculates and outputs the corresponding phases based on the year of birth entered by the user. The program is based on the Chinese Zodiac, so it is only applicable to Chinese culture. The core of the code is the use of conditional statements and operators to calculate and output the user's phases and how to get input from the user.

Above is python write according to the year to determine the details of the Chinese zodiac example, more information about python to determine the Chinese zodiac please pay attention to my other related articles!