invested 2000

gains 0.2 every odd numbered month
gains 0.15 every even numbered month
write function for n months?

i've tried solving this with a formula, but every formula i come up with is wrong.

Could someone tell me how to solve this and plug in the right numbers into a formula?

For the first five months algebrically i got:

1: 2400
2: 2040
3: 2448
4: 2080.8
5: 2496.96

i tried using this formula:
2000(1+0.2)^n

when i plugged in 1 for n i got 2400.
however, when i plugged in 2 for n i got 2880. which isn't right.
so i changed the formula to 2040(1+ .2)^1 I got the right answer

but is there a simple formula where i can just plug in the "n" and get the right amount?

Is there one formula where i can get the answer to any month?

To solve this problem, you can use a for loop in a function to calculate the gains for each month. Here's an example of how you can write the function in Python:

```python
def calculate_gains(n):
investment = 2000
for month in range(1, n+1):
if month % 2 == 0:
gain = investment * 0.15
else:
gain = investment * 0.2
investment += gain
return investment
```

In this function, `n` represents the number of months you want to calculate the gains for. The initial investment is set to 2000. The for loop iterates from 1 to the given number of months.

For each month, the function checks if the month is even or odd using the modulus operator (%). If the month is even, the gain is calculated as 15% of the current investment. If the month is odd, the gain is calculated as 20% of the current investment. The investment is then updated by adding the gain.

Finally, the function returns the total investment at the end of the given number of months.

To calculate the gains for a specific number of months, you can call the function and pass the desired number as an argument, for example:

```python
num_months = 6
total_investment = calculate_gains(num_months)
print(total_investment)
```

This will calculate and print the total investment after 6 months.