1 # -*- coding: utf-8 -*- 2 #定义一个函数,可接收一个或多个数并计算乘积 3 def product(*numbers): 4 s=1 5 for n in numbers: 6 s=s*n 7 return s 8 print(‘请输入一个或多个数,以空格分隔‘) 9 #将输入的字符串转换为数组 10 a=list(map(float,input().strip().split())) 11 #print(a) 12 print(product(*a))
知识点:
>>> def f(x): ... return x * x >>> r = map(f, [1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> list(r) [1, 4, 9, 16, 25, 36, 49, 64, 81]
原文:https://www.cnblogs.com/jianglin1996/p/10744066.html