Page 1 of 1

Reputation:

# Python Loop

Posted 14 February 2011 - 02:22 PM

These are the instructions and my code is written below >>

What I need >> I can't figure out the logic behind creating a for or while loop that'll list my top n fantasies that the guy chooses. As it said, its guaranteed he'll choose a number between 2 and 20.

Part I

1. Start by creating your own module that contains the program trust_fund_bad from the book. That program has 8 categories of expenses. Maybe your taste doesn’t run to Lamborghinis. So change the program so that it uses 8 budget categories that reflect how you would spend the trust fund money if it were yours.

2. Run the program. See if you can figure out why it gets the wrong answer.

4. Call your function to make sure that it works as you expect (namely incorrectly).

Part II

1. In the same module, create a new function called trust_fund_good. Start with the body of your function using the code from trust_fund_good from the book. But again there are the old 8 categories of expenses. So change this second function so that it uses the budget categories you chose for Part I.

2. Call your function to make sure it works correctly.

Part III

Your rich grandfather may have set you up with a trust but he’s also given you a mean trustee who is determined to limit your expenses. He’s asked you for a budget and told you to list 20 budget categories, in descending order of how badly you want them. But he is going to decide how many of them you’re going to get. You are guaranteed that he’ll pick a number between 2 and 20.

1.In the same module, create a new function called trust_fund_monthly. Here’s its outline:

def trust_fund_monthly(n):

"""Will let you have your top n ways of spending money."""

# fantasies is a list of money spending opportunities.

# damages is a matching list of dollar amounts.

fantasies = 20 * [""] # Before we start to fantasize.

damages = 20 * [0] # These just create the lists.

# Now fill in the values.

fantasies[0] = ("Extreme sports")

damages[0] = 10000

fantasies[1] = "truffles"

damages[1] = 5000

## fill in 2 through 19
## print a list of the n allowable fantasies
## print the monthly total of the allowable fantasies

You should fill in the three sections marked with ##. In other words, you need to make your function do the following three things:

a. Fill in the lists fantasies and damages.

b. Print a list of the n allowable fantasies. (Hint: use a loop.)

c. Print the monthly total of the allowable fantasies. (Hint: use another loop.) Make sure to label this number as the monthly total.

2. Call your function to make sure it works correctly.

```

print(
"""
Trust Fund Buddy

Totals your monthly spending so that your trust fund doesn't run out
(and you're forced to get a real job).

Please enter the requested, monthly costs.  Since you're rich, ignore pennies
and use only dollar amounts.

"""
)

car =  input("parking: ")
bike = input("New Fairigns: ")
books = input("All Books: ")
clothing =input("Shoes&Jeans: ")
food = input("Dining out and groceries: ")
bets = input("Poker&other Bet: ")
games = input("Game Server & Vent: ")
investment = input("Invest: ")

total = car + bike + books + clothing + food + bets + games + investment

print("\nGrand Total:", total)

input("\n")

def trust_fund_good():

car =  int(input("parking: "))
bike = int(input("New Fairigns: "))
books = int(input("All Books: "))
clothing = int(input("Shoes&Jeans: "))
food = int(input("Dining out and groceries: "))
bets = int(input("Poker&other Bet: "))
games = int(input("Game Server & Vent: "))
investment = int(input("Invest: "))

total = car + bike + books + clothing + food + bets + games + investment

print("\nGrand Total:", total)

trust_fund_good()

def trust_fund_monthly(n):

"""Will let you have your top n ways of spending money."""

# fantasies is a list of money spending opportunities.

# damages is a matching list of dollar amounts.

fantasies = 20 * [""]       # Before we start to fantasize.

damages = 20 * [0]          # These just create the lists.

fantasies[0] = ("Extreme sports")
damages[0] = 10000
fantasies[1] = "truffles"
damages[1] = 5000
fantasies[2] = ("Extreme sports")
damages[2] = 10000
fantasies[3] = "truffles"
damages[3] = 5000
fantasies[4] = ("Extreme sports")
damages[4] = 10000
fantasies[5] = "truffles"
damages[5] = 5000
fantasies[6] = ("Extreme sports")
damages[6] = 10000
fantasies[7] = "truffles"
damages[7] = 5000
fantasies[8] = ("Extreme sports")
damages[8] = 10000
fantasies[9] = "truffles"
damages[9] = 5000
fantasies[10] = ("Extreme sports")
damages[10] = 10000
fantasies[11] = "truffles"
damages[11] = 5000
fantasies[12] = ("Extreme sports")
damages[12] = 10000
fantasies[13] = "truffles"
damages[13] = 5000
fantasies[14] = ("Extreme sports")
damages[14] = 10000
fantasies[15] = "truffles"
damages[15] = 5000
fantasies[16] = ("Extreme sports")
damages[16] = 10000
fantasies[17] = "truffles"
damages[17] = 5000
fantasies[18] = ("Extreme sports")
damages[18] = 10000
fantasies[19] = "truffles"
damages[19] = 5000

# ill change the names later ..just cant figure out the for loop

input("\n\nPress the enter key to exit.")

```

Is This A Good Question/Topic? 0

## Replies To: Python Loop

### #2 atraub

• Pythoneer

Reputation: 732
• Posts: 1,878
• Joined: 23-December 08

## Re: Python Loop

Posted 14 February 2011 - 02:33 PM

Holy overloaded topics Batman, there's a lot of junk in that post! In the future, try to keep your topics more concise I'm confused what you want to know exactly. So, the program should ask the user for his top n fantasies? First, you'll need a way for a user to choose which fantasy he wants to enter. I'd first print something like this:

```for i in range(len(fantasies)):
print(str(i)+".) "+fantasies[i]+":  "+str(damages[i]))
```

This should (thought I haven't tested it ) print out a listing of all the fantasies. Then you should ask the user for n fantasies (n should be defined somewhere) and then figure out how much the total damage is.

```total = 0
for i in range(n):
choice = input("Which fantasy do you want (Use the corresponding #): ")
total += damages[choice]

```

Is this what you had in mind?

This post has been edited by atraub: 14 February 2011 - 02:34 PM

Reputation:

## Re: Python Loop

Posted 15 February 2011 - 01:45 AM

I think what the instructions are looking for is something very simple like >>

Prompt the user to pick a number of fantasies between 2 and 20..without listing anything. The user will pick a number between 2 and 20. That number will be my top fantasies.
Since your top 20 fantasies are listed in order, it would list the top "whatever number the user chose" fantasies in a list.
Then it would list the monthly total of all of those fantasies.

I just started learning Python and what you wrote is a bit complex for me to understand without looking up the syntax.

I did run it however and got this error: NameError: name 'fantasies' is not defined

### #4 atraub

• Pythoneer

Reputation: 732
• Posts: 1,878
• Joined: 23-December 08

## Re: Python Loop

Posted 15 February 2011 - 07:26 AM

I see. First off, to understand the code, append it to the end of trust_fund_monthly and then run the function (It'll look like this):

```def trust_fund_monthly(n):

"""Will let you have your top n ways of spending money."""

# fantasies is a list of money spending opportunities.

# damages is a matching list of dollar amounts.

fantasies = 20 * [""]       # Before we start to fantasize.

damages = 20 * [0]          # These just create the lists.

fantasies[0] = ("Extreme sports")
damages[0] = 10000
fantasies[1] = "truffles"
damages[1] = 5000
fantasies[2] = ("Extreme sports")
damages[2] = 10000
fantasies[3] = "truffles"
damages[3] = 5000
fantasies[4] = ("Extreme sports")
damages[4] = 10000
fantasies[5] = "truffles"
damages[5] = 5000
fantasies[6] = ("Extreme sports")
damages[6] = 10000
fantasies[7] = "truffles"
damages[7] = 5000
fantasies[8] = ("Extreme sports")
damages[8] = 10000
fantasies[9] = "truffles"
damages[9] = 5000
fantasies[10] = ("Extreme sports")
damages[10] = 10000
fantasies[11] = "truffles"
damages[11] = 5000
fantasies[12] = ("Extreme sports")
damages[12] = 10000
fantasies[13] = "truffles"
damages[13] = 5000
fantasies[14] = ("Extreme sports")
damages[14] = 10000
fantasies[15] = "truffles"
damages[15] = 5000
fantasies[16] = ("Extreme sports")
damages[16] = 10000
fantasies[17] = "truffles"
damages[17] = 5000
fantasies[18] = ("Extreme sports")
damages[18] = 10000
fantasies[19] = "truffles"
damages[19] = 5000
for i in range(len(fantasies)):
print(str(i)+".) "+fantasies[i]+":  "+str(damages[i]))
```

Once you run it, it'll be clear as day what it's doing

As for your current problem, I think I understand now. You just want to get the first n items starting at 0. That's easy enough.
```total = 0
for i in range(n):
total+=damages[i]
```

This will add up all the items from position 0 to n-1 and keep that number in total. There are other ways to accomplish this, but using a loop is part of your instructions.

P.S. Any interest in creating a free account and becoming a regular member here at DIC? It's always nice to see some new faces on my Python board

This post has been edited by atraub: 15 February 2011 - 07:28 AM

Reputation:

## Re: Python Loop

Posted 16 February 2011 - 02:36 AM

Sorry to keep bothering you and I'll def. make an account since I plan on learning python and other prog. langs. It's just that I am taking some finance courses and they eat up a lot of my time and then I barely have left to actually open up my python book and read it.

The code prints the list of of all fantasies. Then before I could add the total of anything, I have to ask the user to input a number between 2&20, print list of top whatever number he chose fantasies, then compute total damages of those top fantasies in that list.

Here's what I have >> Computing the total damages of the n list is not working for some reason. It doesn't give an error or return anything.

```
for i in range(n):
print(str(i)+".) "+fantasies[i]+":  "+str(damages[i])) # prints list of all fantasies

total = 0
for i in range(n):
total+=damages[i]
return(total)

trust_fund_monthly(int(input("Pick a number between 2&20\n")))

```

Reputation:

## Re: Python Loop

Posted 16 February 2011 - 02:54 AM

nevermind. i changed the return(total) to print(total) and it worked. I am still workign on other parts of this program and next time I post, I'll have a username you can refer to when replying

Reputation:

## Re: Python Loop

Posted 16 February 2011 - 08:27 PM

trust_fund_monthly(int(input("Pick a number between 2&20\n")))
Pick a number between 2&20
8
0.) Extreme Sports: 10000
10000
15000
30000
40000
60000
65000
90000
91500
1.) truffles: 5000
10000
15000
30000
40000
60000
65000
90000
91500
2.) Hunting: 15000
10000
15000
30000
40000
60000
65000
90000
91500
3.) Cars: 10000
10000
15000
30000
40000
60000
65000
90000
91500
4.) White Water Rafting: 20000
10000
15000
30000
40000
60000
65000
90000
91500
5.) Video Games: 5000
10000
15000
30000
40000
60000
65000
90000
91500
6.) Racing: 25000
10000
15000
30000
40000
60000
65000
90000
91500
7.) Zip Lining: 1500
10000
15000
30000
40000
60000
65000
90000
91500
8.) Traveling: 50000
10000
15000
30000
40000
60000
65000
90000
91500
9.) Paying for Homework: 10000
10000
15000
30000
40000
60000
65000
90000
91500
10.) Boating: 35000
10000
15000
30000
40000
60000
65000
90000
91500
11.) Movie Making: 125000
10000
15000
30000
40000
60000
65000
90000
91500
12.) Golfing: 25000
10000
15000
30000
40000
60000
65000
90000
91500
13.) Eating: 15000
10000
15000
30000
40000
60000
65000
90000
91500
14.) clothes: 10000
10000
15000
30000
40000
60000
65000
90000
91500
15.) Paintball: 6000
10000
15000
30000
40000
60000
65000
90000
91500
16.) Never Working: 750000
10000
15000
30000
40000
60000
65000
90000
91500
17.) Technology: 45000
10000
15000
30000
40000
60000
65000
90000
91500
18.) Crying: 12000
10000
15000
30000
40000
60000
65000
90000
91500
19.) Boredom: 65000
10000
15000
30000
40000
60000
65000
90000
91500

Is that what is is supposed to look like? (i have to do the same assignment)

Reputation:

## Re: Python Loop

Posted 16 February 2011 - 08:29 PM

This was my code for that:
```def trust_fund_monthly(n):
"""Will let you have your top n ways of spending money."""
# fantasies is a list of money spending opportunities.
# damages is a matching list of dollar amounts.
fantasies = 20 * [""]       # Before we start to fantasize.
damages = 20 * [0]          # These just create the lists.
fantasies[0] = ("Extreme Sports")
damages[0] = 10000
fantasies[1] = "truffles"
damages[1] = 5000
fantasies[2] = ("Hunting")
damages[2] = 15000
fantasies[3] = ("Cars")
damages[3] = 10000
fantasies[4] = ("White Water Rafting")
damages[4] = 20000
fantasies[5] = ("Video Games")
damages[5] = 5000
fantasies[6] = ("Racing")
damages[6] = 25000
fantasies[7] = ("Zip Lining")
damages[7] = 1500
fantasies[8] = ("Traveling")
damages[8] = 50000
fantasies[9] = ("Paying for Homework")
damages[9] = 10000
fantasies[10] = ("Boating")
damages[10] = 35000
fantasies[11] = ("Movie Making")
damages[11] = 125000
fantasies[12] = ("Golfing")
damages[12] = 25000
fantasies[13] = ("Eating")
damages[13] = 15000
fantasies[14] = ("clothes")
damages[14] = 10000
fantasies[15] = ("Paintball")
damages[15] = 6000
fantasies[16] = ("Never Working")
damages[16] = 750000
fantasies[17] = ("Technology")
damages[17] = 45000
fantasies[18] = ("Crying")
damages[18] = 12000
fantasies[19] = ("Boredom")
damages[19] = 65000
for i in range(len(fantasies)):
print(str(i)+".) "+fantasies[i]+":  "+str(damages[i]))
total = 0
for i in range(n):
total+=damages[i]
print(total)
```

This post has been edited by atraub: 17 February 2011 - 07:23 AM

Reputation:

## Re: Python Loop

Posted 16 February 2011 - 09:12 PM

hmmm, that's not what i got....

Pick a number between 2&20
2
0.) A new car: 100000
1.) Clothes: 1000
2.) Food: 2000
3.) Games: 500
4.) Camera Equipment: 2000
5.) Vacatation Getaway:
6.) Movies: 2500
7.) Candy: 500
8.) Lobster: 90
9.) Shoes: 500
10.) Computer: 1000
11.) Rims: 3000
12.) TV: 2000
13.) Racing Class: 3500
14.) Watch: 1000
15.) Sound System: 2000
16.) House Maid: 4000
17.) Airplane: 350000
18.) Boat: 25000
19.) Rifle: 2500
101000

It adds up the first two since i inputed 2. isn't it suppose to be random, also it has to print out the 2 choices that was picked? this is where im lost.

my code is

```# Trust Fund Monthy

def trust_fund_monthly(n):

"""Will let you have your top n ways of spending money."""

fantasies = 20 * [""]
damages = 20 * [""]

fantasies[0] = ("A new car")
damages[0] = 100000
fantasies[1] = ("Clothes")
damages [1] = 1000
fantasies[2] = ("Food")
damages [2] =2000
fantasies[3] = ("Games")
damages [3] =500
fantasies[4] = ("Camera Equipment")
damages [4] =2000
fantasies[5] = ("Vacatation Getaway")
damages [6] =2500
fantasies[6] = ("Movies")
damages [7] =500
fantasies[7] = ("Candy")
damages [8] =200
fantasies[8] = ("Lobster")
damages [8] =90
fantasies[9] = ("Shoes")
damages [9] =500
fantasies[10] = ("Computer")
damages [10] =1000
fantasies[11] = ("Rims")
damages [11] =3000
fantasies[12] = ("TV")
damages [12] = 2000
fantasies[13] = ("Racing Class")
damages [13] =3500
fantasies[14] = ("Watch")
damages [14] =1000
fantasies[15] = ("Sound System")
damages [15] =2000
fantasies[16] = ("House Maid")
damages [16] =4000
fantasies[17] = ("Airplane")
damages [17] =350000
fantasies[18] = ("Boat")
damages [18] =25000
fantasies[19] = ("Rifle")
damages [19] = 2500

for i in range(len(fantasies)):
print(str(i)+".) "+fantasies[i]+":  "+str(damages[i]))

total = 0
for i in range(n):
total+=damages[i]
print(total)

trust_fund_monthly(int(input("Pick a number between 2&20\n")))

```

Reputation:

## Re: Python Loop

Posted 16 February 2011 - 10:05 PM

```# Trust Fund Buddy - Bad

print (
"""
Trust Fund Buddy

Totals your monthly spending so that your trust fund doesn't run out
(and you're forced to get a real job).

Please enter the requested, monthly costs. Since you're rich, ingore pennies
and use only dollar amounts.

"""
)

Car = input("BMW M3 Maintenance: ")
Clothes = input("Clothes: ")
Food = input("Food: ")
Games = input("Games: ")
Investment = input("Investment: ")
Parties = input("parties: ")
Girlfriend = input("Girlfriend: ")

total = Car + Clothes + Food + Games + Investment + Parties + Girlfriend

print("\nGrand Total:", total)

input("\n\nPress the enter key to exit.")

# Trust Fund Buddy - Good

print (
"""
Trust Fund Buddy

Totals your monthly spending so that your trust fund doesn't run out
(and you're forced to get a real job).

Please enter the requested, monthly costs. Since you're rich, ingore pennies
and use only dollar amounts.

"""
)

Car = int(input("BMW M3 Maintenance: "))
Clothes = int(input("Clothes: "))
Food = int(input("Food: "))
Games = int(input("Games: "))
Investment = int(input("Investment: "))
Parties = int(input("parties: "))
Girlfriend = int(input("Girlfriend: "))

total = Car + Clothes + Food + Games + Investment + Parties + Girlfriend

print("\nGrand Total:", total)

input("\n\nPress the enter key to exit.")

# Trust Fund Monthy

def trust_fund_monthly(n):

"""Will let you have your top n ways of spending money."""

fantasies = 20 * [""]
damages = 20 * [""]

fantasies[0] = ("A new car")
damages[0] = 100000
fantasies[1] = ("Clothes")
damages [1] = 1000
fantasies[2] = ("Food")
damages [2] =2000
fantasies[3] = ("Games")
damages [3] =500
fantasies[4] = ("Camera Equipment")
damages [4] =2000
fantasies[5] = ("Vacation Getaway")
damages [5] =2500
fantasies[6] = ("Movies")
damages [6] =500
fantasies[7] = ("Candy")
damages [7] =200
fantasies[8] = ("Lobster")
damages [8] =90
fantasies[9] = ("Shoes")
damages [9] =500
fantasies[10] = ("Computer")
damages [10] =1000
fantasies[11] = ("Rims")
damages [11] =3000
fantasies[12] = ("TV")
damages [12] = 2000
fantasies[13] = ("Racing Class")
damages [13] =3500
fantasies[14] = ("Watch")
damages [14] =1000
fantasies[15] = ("Sound System")
damages [15] =2000
fantasies[16] = ("House Maid")
damages [16] =4000
fantasies[17] = ("Airplane")
damages [17] =350000
fantasies[18] = ("Boat")
damages [18] =25000
fantasies[19] = ("Rifle")
damages [19] = 2500

for i in range(n):
print(str(i)+".) "+fantasies[i]+":  "+str(damages[i]))

total = 0
for i in range(n):
total+=damages[i]
print(total)

trust_fund_monthly(int(input("Pick a number between 2&20\n")))

```

Reputation:

## Re: Python Loop

Posted 16 February 2011 - 10:41 PM

```def trust_fund_monthly(n):

"""Will let you have your top n ways of spending money."""

fantasies = 20 * [""]
damages = 20 * [""]

fantasies[0] = ("Hunting")
damages[0] = 10000
fantasies[1] = ("Clothes")
damages [1] = 1000
fantasies[2] = ("Food")
damages [2] =2000
fantasies[3] = ("Games")
damages [3] =5000
fantasies[4] = ("Skiing")
damages [4] =20000
fantasies[5] = ("Vacatations")
damages [6] =25000
fantasies[6] = ("Entertainment")
damages [7] =5000
fantasies[7] = ("Snacks")
damages [8] =1000
fantasies[8] = ("Fine Dining")
damages [8] =15000
fantasies[9] = ("Mountain Climbing")
damages [9] =14000
fantasies[10] = ("Computer")
damages [10] =10000
fantasies[11] = ("Cars")
damages [11] =30000
fantasies[12] = ("Technology")
damages [12] = 20000
fantasies[13] = ("Racing")
damages [13] =15000
fantasies[14] = ("White Water Rafting")
damages [14] =5000
fantasies[15] = ("Zip Lining")
damages [15] =2000
fantasies[16] = ("Maintenance Staff")
damages [16] =9000
fantasies[17] = ("Airplane")
damages [17] =350000
fantasies[18] = ("Boat")
damages [18] =25000
fantasies[19] = ("Guns")
damages [19] = 15000

for i in range(len(fantasies)):
print(str(i)+".) "+fantasies[i]+":  "+str(damages[i]))

total = 0
for i in range(n):
total+=damages[i]
print(total)
```

That is what my code is and I think I ahve the same problem you do.

This post has been edited by atraub: 17 February 2011 - 07:23 AM
Reason for edit:: Use code tags

Reputation:

## Re: Python Loop

Posted 16 February 2011 - 11:42 PM

Ok this is the final product!!!!!!!!!!!!!!

```# Trust Fund Buddy - Bad

print (
"""
Trust Fund Buddy

Totals your monthly spending so that your trust fund doesn't run out
(and you're forced to get a real job).

Please enter the requested, monthly costs. Since you're rich, ingore pennies
and use only dollar amounts.

"""
)

Car = input("BMW M3 Maintenance: ")
Clothes = input("Clothes: ")
Food = input("Food: ")
Games = input("Games: ")
Investment = input("Investment: ")
Parties = input("parties: ")
Vacation = input("Vacation: ")
Girlfriend = input("Girlfriend: ")

total = Car + Clothes + Food + Games + Investment + Parties + Vacation + Girlfriend

print("\nGrand Total:", total)

input("\n\nPress the enter key to exit.")

# Trust Fund Buddy - Good

print (
"""
Trust Fund Buddy

Totals your monthly spending so that your trust fund doesn't run out
(and you're forced to get a real job).

Please enter the requested, monthly costs. Since you're rich, ingore pennies
and use only dollar amounts.

"""
)

Car = int(input("BMW M3 Maintenance: "))
Clothes = int(input("Clothes: "))
Food = int(input("Food: "))
Games = int(input("Games: "))
Investment = int(input("Investment: "))
Parties = int(input("parties: "))
Vacation = int(input("Vacation: "))
Girlfriend = int(input("Girlfriend: "))

total = Car + Clothes + Food + Games + Investment + Parties + Vacation + Girlfriend

print("\nGrand Total:", total)

input("\n\nPress the enter key to exit.")

# Trust Fund Monthy

def trust_fund_monthly(n):

"""Will let you have your top n ways of spending money."""

fantasies = 20 * [""]
damages = 20 * [""]

fantasies[0] = ("A new car")
damages[0] = 100000
fantasies[1] = ("Clothes")
damages [1] = 1000
fantasies[2] = ("Food")
damages [2] =2000
fantasies[3] = ("Games")
damages [3] =500
fantasies[4] = ("Camera Equipment")
damages [4] =2000
fantasies[5] = ("Vacation Getaway")
damages [5] =2500
fantasies[6] = ("Movies")
damages [6] =500
fantasies[7] = ("Candy")
damages [7] =200
fantasies[8] = ("Lobster")
damages [8] =90
fantasies[9] = ("Shoes")
damages [9] =500
fantasies[10] = ("Computer")
damages [10] =1000
fantasies[11] = ("Rims")
damages [11] =3000
fantasies[12] = ("TV")
damages [12] = 2000
fantasies[13] = ("Racing Class")
damages [13] =3500
fantasies[14] = ("Watch")
damages [14] =1000
fantasies[15] = ("Sound System")
damages [15] =2000
fantasies[16] = ("House Maid")
damages [16] =4000
fantasies[17] = ("Airplane")
damages [17] =350000
fantasies[18] = ("Boat")
damages [18] =25000
fantasies[19] = ("Rifle")
damages [19] = 2500

for i in range(n):
print(str(i)+".) "+fantasies[i]+":  "+str(damages[i]))

print("monthly total")

total = 0
for i in range(n):
total+=damages[i]
print(total)

trust_fund_monthly(int(input("Pick a number between 2&20\n")))

# Trust Fund annual

def trust_fund_annual(n):

"""Will let you have your top n ways of spending money."""

fantasies = 20 * [""]
damages = 20 * [""]

fantasies[0] = ("A new car")
damages[0] = 100000
fantasies[1] = ("Clothes")
damages [1] = 1000
fantasies[2] = ("Food")
damages [2] =2000
fantasies[3] = ("Games")
damages [3] =500
fantasies[4] = ("Camera Equipment")
damages [4] =2000
fantasies[5] = ("Vacation Getaway")
damages [5] =2500
fantasies[6] = ("Movies")
damages [6] =500
fantasies[7] = ("Candy")
damages [7] =200
fantasies[8] = ("Lobster")
damages [8] =90
fantasies[9] = ("Shoes")
damages [9] =500
fantasies[10] = ("Computer")
damages [10] =1000
fantasies[11] = ("Rims")
damages [11] =3000
fantasies[12] = ("TV")
damages [12] = 2000
fantasies[13] = ("Racing Class")
damages [13] =3500
fantasies[14] = ("Watch")
damages [14] =1000
fantasies[15] = ("Sound System")
damages [15] =2000
fantasies[16] = ("House Maid")
damages [16] =4000
fantasies[17] = ("Airplane")
damages [17] =350000
fantasies[18] = ("Boat")
damages [18] =25000
fantasies[19] = ("Rifle")
damages [19] = 2500

for i in range(n):
print(str(i)+".) "+fantasies[i]+":  "+str(damages[i]))

print("Anual Total:")

total = 0
for i in range(n):
total+=damages[i] * 12
print(total)

diff = 0
for i in range(n):
diff=846678754 - (damages[i] * 12)
if diff > 0:
print ("you spent "+str(diff)+" less than Beachland this year.  Congratulations on not wasting money!")
elif diff == 0:
print ("you spent "+str(diff)+" exactly the same amount as Beachland this year.  Congratulations on becoming an island nation!")
elif diff < 0:
print ("you spent "+str(diff)+" more than Beachland this year.  Congratulations on becoming an island nation!")

trust_fund_annual(int(input("Pick a number between 2&20\n")))

```

Reputation:

## Re: Python Loop

Posted 17 February 2011 - 07:34 AM

Thank you. You are awesome