How to use python to output constellations? Here are the specific methods:
Ideas:
1. Define a get_constellation (month, date) function to Get date of birth.
2. Create dates and constellations to store the corresponding days and constellations respectively.
3. Use the if statement to determine whether the entered number of days is less than the number of days corresponding to the birth month minus one.
4. If yes, return the constellation corresponding to the month minus one. If not, return the constellation corresponding to the birth month.
5. Output the results input by the user.
Related recommendations: "Python Video Tutorial"
def get_constellation(month, date): dates = (21, 20, 21, 21, 22, 22, 23, 24, 24, 24, 23, 22) constellations = ("摩羯", "水瓶", "双鱼", "白羊", "金牛", "双子", "巨蟹", "狮子", "处女", "天秤", "天蝎", "射手", "摩羯") if date < dates[month-1]: return constellations[month-1] else: return constellations[month] print (get_constellation(7, 10) )
The results are as follows:
巨蟹
The above is the detailed content of How to use python to output constellation. For more information, please follow other related articles on the PHP Chinese website!