python 8.23 定义函数

def mul(*x):
if len(x)==0:
raise TypeError(‘hello world‘)
else:
for ii in x:
if not isinstance(ii,(int,float)):
raise TypeError(‘hello world‘)
n = 1
for i in x:
n = n*i
return n
print(mul())

 

import random
def get_name(n,*a):
if len(a)<n:
raise ValueError(‘n不能超过名单名字数‘)
a = list(a)
strs = ‘‘
for i in range(n):
name = a.pop(random.randrange(len(a)))
strs+=name+‘,‘
return strs.strip(‘,‘)
print(get_name(4,‘马大哈‘,‘王小明‘,‘张天宇‘,‘李明‘))

python 8.23 定义函数

上一篇:以下Java程序运行的结果是:


下一篇:springBoot整合mybatis