计算多数的乘积(Python实现)


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))

计算两数乘积以及多数乘积的结果~

运行结果:

--------------------- ┑( ̄Д  ̄)┍ --------------------------

作者:0yst3r[一只在安全领域努力奋斗的小菜鸡]
来源:博客园[ https://www.cnblogs.com/0yst3r-2046/ ] 引用时请注明来源哦~

(๑•̀ㅂ•́)و✧ヽ(✿゚▽゚)ノ(*^▽^*) φ(≧ω≦*)♪
如果本文对你有用,本人不胜欢喜。
The world is your oyster.
原文地址:https://www.cnblogs.com/0yst3r-2046/p/10711706.html