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设计】。

相关文章

Windows中安装使用Virtualenv来创建独立Python环境

Windows中安装使用Virtualenv来创建独立Python环境

0、什么时候会用到virtualenv? 假设系统中的两个应用,其中A应用对库LibFoo的版本要求为1,而B应用对同一个库LibFoo的版本要求为2,两个应用对同一个库的要求想冲突了,...

Python实现语音识别和语音合成功能

Python实现语音识别和语音合成功能

声音的本质是震动,震动的本质是位移关于时间的函数,波形文件(.wav)中记录了不同采样时刻的位移。 通过傅里叶变换,可以将时间域的声音函数分解为一系列不同频率的正弦函数的叠加,通过频率谱...

python3实现elasticsearch批量更新数据

废话不多说,直接上代码! updateBody = { "query":{ "range":{ "write_date": { "g...

Python使用pip安装报错:is not a supported wheel on this platform的解决方法

Python使用pip安装报错:is not a supported wheel on this platform的解决方法

本文讲述了Python使用pip安装报错:is not a supported wheel on this platform的解决方法。分享给大家供大家参考,具体如下: 可能的原因1:安...

在Python的Flask中使用WTForms表单框架的基础教程

在Python的Flask中使用WTForms表单框架的基础教程

下载和安装 安装 WTForms 最简单的方式是使用 easy_install 和 pip: easy_install WTForms # or pip install WTForm...