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

相关文章

对pandas中iloc,loc取数据差别及按条件取值的方法详解

Dataframe使用loc取某几行几列的数据: print(df.loc[0:4,['item_price_level','item_sales_level','item_coll...

Python修改MP3文件的方法

本文实例讲述了Python修改MP3文件的方法。分享给大家供大家参考。具体如下: 用这个程序修改后的MP3比原来要小一些了,因为一张图片被删除了,起到了给MP3"瘦身"的作用。在一些mp...

pytorch中的embedding词向量的使用方法

Embedding 词嵌入在 pytorch 中非常简单,只需要调用 torch.nn.Embedding(m, n) 就可以了,m 表示单词的总数目,n 表示词嵌入的维度,其实词嵌入就...

python转换摩斯密码示例

复制代码 代码如下:CODE = {'A': '.-',     'B': '-...',   'C': '-.-.',&nb...

从django的中间件直接返回请求的方法

实例如下所示: #coding=utf-8 import json import gevent from django.http import HttpResponse from s...