1 # -*- coding: utf-8 -*- 2 # sum_of_products.py 3 # @author 0yst3r 4 # @description 两数之积及多数之积 5 # @created Mon Apr 15 2019 15:22:24 GMT+0800 (中国标准时间) 6 # @last-modified Mon Apr 15 2019 17:04:25 GMT+0800 (中国标准时间) 7 # 8 9 ''' 10 # 两数之积 11 def product(x, y): 12 return x * y 13 14 15 print('x*y=', product(2, 5)) 16 ''' 17 18 num_list = [] # 乘数列表 19 20 21 def the_input(count=eval(input("输入乘数的总个数:"))): 22 23 for i in range(count): 24 N = eval(input("依次输入乘数:")) 25 num_list.append(N) 26 print("一共有", count, "个要相乘的数") 27 print("把这些乘数依次放在列表里面:", num_list) 28 29 30 the_input() 31 32 33 def get_multi(*num): 34 sum = 1 35 for n in num: 36 sum = sum * n 37 return sum 38 39 40 print("这些数相乘的总乘积为:", get_multi(*num_list))
计算两数乘积以及多数乘积的结果~
运行结果: