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

yipeiwu_com5年前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实现在线暴力破解邮箱账号密码功能示例【测试可用】

本文实例讲述了Python实现在线暴力破解邮箱账号密码功能。分享给大家供大家参考,具体如下: dic 字典格式如下(mail.txt) : username@gmail.com:pa...

python使用paramiko模块通过ssh2协议对交换机进行配置的方法

该代码用的是paramiko模块,python版本是python2.7 下面上源码 # -*- coding: utf-8 -*- import paramiko import t...

python 将字符串转换成字典dict

复制代码 代码如下:JSON到字典转化:dictinfo = simplejson.loads(json_str) 输出dict类型 字典到JSON转化:jsoninfo = simpl...

使用Python实现画一个中国地图

使用Python实现画一个中国地图

为什么是Python 先来聊聊为什么做数据分析一定要用Python或R语言。编程语言这么多种,Java, PHP都很成熟,但是为什么在最近热火的数据分析领域,很多人选择用Python语言...

深入分析在Python模块顶层运行的代码引起的一个Bug

然后我们在Interactive Python prompt中测试了一下: >>> import subprocess >>> subproc...