1、函数

   语法  def my_function():

        .....

   当需要多次使用同样的操作时,可将内容写成函数形式以方便调用

   函数可以分为无参数和有参数(1或多个)

   

def my_function():
print('hello , world')
def add(a,b):
print(a+b)
def sum(a,b):
c=a+1
d=b+1
return c,d

my_function()
add(1,5)
e,f = sum(5,8)
print(e)
print(f)
>>>hello . world
  6
  6
  9




test1 根据出生日期,返回对应的星座及其性格特点:

def get_constellation(birthday):
constellation = ""
constellation_value = ""
if 3.21 <= birthday <= 4.19:
constellation = "白羊座"
constellation_value = "有一种让人看见就觉得开心的感觉,阳光、乐观、坚强,性格直来直去,就是有点小脾气。"
elif 4.20 <= birthday <= 5.20:
constellation = "金牛座"
constellation_value = "很保守,喜欢稳定,一旦有什么变动就会觉得心里不踏实,性格比较慢熟,是个理财高手。"
elif 5.21 <= birthday <= 6.21:
constellation = "双子座"
constellation_value = "喜欢追求新鲜感,有点小聪明,耐心不够,因你的可爱性格会让很多人喜欢和你做朋友"
elif 6.22 <= birthday <= 7.22:
constellation = "巨蟹座"
constellation_value = "情绪容易敏感,缺乏安全感,做事情有坚持到底的毅力,为人重情重义,对朋友和家人特别忠实。"
elif 7.23 <= birthday <= 8.22:
constellation = "狮子座"
constellation_value = "有着远大的理想,总想靠自己的努力成为人上人,总是期待被仰慕被崇拜的感觉。"
elif 8.23 <= birthday <= 9.22:
constellation = "处女座"
constellation_value = "坚持追求自己的完美主义者。"
elif 9.23 <= birthday <= 10.23:
constellation = "天秤座"
constellation_value = "追求平等、和谐,交际能力强,因此朋友比较多,最大的缺点就是面对选择时总是犹豫不决。"
elif 10.24 <= birthday <= 11.22:
constellation = "天蝎座"
constellation_value = "精力旺盛,占有欲强,对于生活很有目标,不达目的誓不罢休,复仇心重。"
elif 11.23 <= birthday <= 12.21:
constellation = "射手座"
constellation_value = "崇尚自由,勇敢、果断、独立,身上有一股勇往直前的劲儿,只要想做就能做。"
elif 12.22 <= birthday <= 12.31 or 1.1 <= birthday <= 1.19:
constellation = "摩羯座"
constellation_value = "是最优耐心的,做事最小心。做事脚踏实地,比较固执,不达目的不罢休,而且非常勤奋。"
elif 1.20 <= birthday <= 2.18:
constellation = "水瓶座"
constellation_value = "人很聪明,最大的特点是创新,追求独一无二的生活,个人主义色彩很浓的星座。"
elif 2.19 <= birthday <= 3.20:
constellation = "双鱼座"
constellation_value = "集所有星座的优缺点于一身,最大的有点是有一颗善良的心,愿意帮助别人。"
return constellation, constellation_value

Get = get_constellation(1.2)
print(Get)



posted on 2022-02-09 10:49  jer-L  阅读(35)  评论(0)    收藏  举报