帮助python项目 [英] help with python project

查看:73
本文介绍了帮助python项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

写一个正式程序,它取一个偶数列表并打印并返回一个列表,其中输入列表中的每个偶数都乘以它后面的奇数,每个奇数除以偶数在它之后。



例如[1,2,3,4] - > [0.5,2,0.75,12]



i有这个,但我不知道它是不是很好



Write a "formal" program that takes an even number list and prints and returns a list in which every even number from the input list has been multiplied by the odd number behind it and every odd number has been divided by the even number after it.

eg [1,2,3,4] -> [0.5, 2, 0.75, 12]

i have this but i don't know if it is good

def numprogram(l):
    count = 0
    for i in l:
        count +=1
        if i % 2 == 0:
            l[i] = i * (i-1)
            l += l[i]
        else:
            l[i] = i / (i+1)
            l += l[i]

推荐答案

我在代码中做了一些更改。您需要的结果。 [0.5,2,0.75,12]。



I have done some changes in your code. Result as you required. [0.5, 2, 0.75, 12].

def numprogram(l):
    temp = list()
    count = 0
    for i in l:
        count +=1
        if i % 2 == 0:
            l =  i * (i-1)
            temp.append(l)
        else:
            l = i/float((i+1))
            temp.append(l)
    return temp
            
print numprogram([1,2,3,4])


这篇关于帮助python项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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