python 输入一个数n,求n个数求乘或求和的实例

yipeiwu_com6年前Python基础

求和

try:
 while True:
  n=input()
  s=1
  for x in raw_input().split():
   s=s+int(x)
  print s
except EOFError:
 exit()

求乘

try:
 while True:
  n=input()
  s=1
  for x in raw_input().split():
   s=s*int(x)
  print s
except EOFError:
 exit()

以上这篇python 输入一个数n,求n个数求乘或求和的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python FTP批量下载/删除/上传实例

python FTP批量下载/删除/上传实例

最近几天,学习python3的对FTP操作,做下总结!!!! 1.FTP链接 这样写的好处就是如果报错,很快就能找到错在哪里,方便找到问题。 2.FTP文件批量下载 有点要注意的:...

python 中的int()函数怎么用

int(x, [base]) 功能: 函数的作用是将一个数字或base类型的字符串转换成整数。 函数原型: int(x=0) int(x, base=10),base缺省值为10,也就是...

python中的reduce内建函数使用方法指南

官方解释: Apply function of two arguments cumulatively to the items of iterable, from left to r...

python编程线性回归代码示例

python编程线性回归代码示例

 用python进行线性回归分析非常方便,有现成的库可以使用比如:numpy.linalog.lstsq例子、scipy.stats.linregress例子、pandas.o...

对python sklearn one-hot编码详解

one-hot编码的作用 使用one-hot编码,将离散特征的取值扩展到了欧式空间,离散特征的某个取值就对应欧式空间的某个点 将离散特征通过one-hot编码映射到欧式空间,是因为,在回...