如何汇总列表的特定元素? [英] How do I sum specific elements of a list?

查看:61
本文介绍了如何汇总列表的特定元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

获取偶数和奇数位置上元素的算术平均值。



我尝试过:



Get the arithmetic mean of the elements on the even and odd positions.

What I have tried:

import random
a=input
s=0
x=0
l=random.sample((1,30),a)
for i in range(1,a+1) :
   if i %2 ==0 :
        s+=s+element
        r+=1
   else :
        x+=x+element
        t+=1
o=s/r
print o
z=x/t
print z

推荐答案

你从哪里得到这段代码?你对此毫无头绪。例如:

1.什么是
Where did you get this code from? You have no clue about it. For example:
1. what is
a=input



2.什么是

?
2. what is

random.sample((1,30),a)



3.什么是

?
3. what is

element



4.更多语法和逻辑错误...

你真的必须开始学习Python [ ^ ]正确。 BTW,沟渠Python 2,去Python 3。

?
4. Many more syntax and logical errors...
You really have to start to Learn Python[^] properly. BTW, ditch Python 2, go for Python 3.


这篇关于如何汇总列表的特定元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆