multiply even numbers, add odd numbers
<p>I'm trying to solve how to multiply all even numbers in a list with 2, and add all odd numbers with 7. And then present the list in an descending order. It has to be with a function that takes the list as argument.</p>

<p>I found this here on stackoverflow, but it's not really what I'm after, since the example sums up the even numbers to one product.</p>

<p>This is my code:</p>

<pre><code>L = [45, 22, 2, 498, 78]

def EvenOdd(L):

product = 2
resp = 7
elem = None

for elem, val in enumerate(L):
elem += 1
if elem % 2 == 0:
   product *= elem
if elem % 2 == 1:
   resp += elem
   result = L[elem]
   result.sort()
   result.reverse()
print(result)
</code></pre>

<p>You can go through the list and check whether the number is even or not. Then do your multiplication/addition depending on the result. An example is shown below:</p>

<pre><code>original_list = [45, 22, 2, 498, 78]
new_list = []

for number in original_list:
    if number % 2 == 0: #check to see if the number is even
        new_list.append(number*2)

    else:
        new_list.append(number+7)

sort_list = sorted(new_list)
descending_list = sort_list[::-1]
print (original_list)
print (descending_list)
</code></pre>

<p>The output of which gives:</p>

<pre><code>[45, 22, 2, 498, 78]
[996, 156, 52, 44, 4]
</code></pre>

python list function