怎样应用python输出星座?下面给人人带来具体方法:
思绪:
1、定义一个get_constellation(month,date)函数,来猎取诞生日期。
2、建立一个dates和constellations分别来贮存对应的日和星座。
3、用if语句推断输入的日数是不是小于诞生月份减一所对应的日数。
4、如果是就返回月份减一所对应的星座,不是就返回诞生月份所对应的星座。
5、输出用户输入的效果。
相干引荐:《Python视频教程》
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) )
效果以下:
巨蟹
以上就是怎样应用python输出星座的细致内容,更多请关注ki4网别的相干文章!