8.函数

# 函数
# 1.功能性
# 2.隐藏细节
# 3.避免编写重复代码
# 4.
# print()
# round()

a = 1.12386
# 保留3位小数
result=round(a,3)
print(result)
# 定义函数
# def funcname(paramter_list)
#     pass

# 1.参数列表可以没有
# 2.return value none

# import sys
# sys.setrecursionlimit(1000000)
# 1.实现2个数字的相加
# def add(x,y):
#     result = x + y
#     return result

# # 2.打印输入的参数
# def print_code(code):
#     print(code)
    
# a = add(1,2)
# b = print_code('python')
# print(a,b)


def damage(skill1,skill2):
    damage1 = skill1 * 3
    damage2 = skill2 * 2 + 10
    return damage1,damage2

# damages = damage(1,2)
# print(type(damages)) # 元组
# print(damages)

skill1_damages,skill2_damages = damage(1,2)
# 序列解包
print(skill1_damages,skill2_damages)
#  a = 1
#  b = 2
#  c = 3
 
#  a,b,c = 1,2,3


#  d = 1,2,3
#  print(type(d))
#  a,b,c = d
#  print(a,b,c)

a=b=c=1
print(a,b,c)
# 参数:
# 1.必须参数
# 2.关键字参数
def add(x,y):
    # 形参
    result = x + y
    return result
# 关键字参数
c = add(x=3,y=2)

def print_student_files(name,gender='',age=18,college='北京大学'):
    print('我叫' + str(name))
    print('我今年' + str(age) + '')
    print('我是' + str(gender) + '')
    print('我再' + str(college) + '上学')

print_student_files('张三','',18,'北京大学')
print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
print_student_files('李四')
print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
print_student_files('王五')
print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
print_student_files('王晓','',16)
print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
print_student_files('果果',age=17,college='中国矿业大学')

 

posted @ 2018-04-16 18:12  邹柯  阅读(138)  评论(0编辑  收藏  举报