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.
3. Convert your code to a callable function named trust_fund_bad.
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.
# Bad Trust Fund Buddy
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.
"""
)
def trust_fund_bad():
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")
trust_fund_bad()
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.")

New Topic/Question
Reply
MultiQuote







|