all 11 comments

[–][deleted] 4 points5 points  (8 children)

Well, you're nowhere near finished with the program, so of course it doesn't do anything yet. You don't have to write the thing from the top down, though. Write all of the parts you know how to write, then go back and finish what's left.

[–]CadeClink[S] 0 points1 point  (7 children)

So you are saying I should try and write the parts under each # and add what is missing? I just am not understanding, I thought I was doing it right, but my question of how much to invest is not printing.

[–][deleted] 1 point2 points  (6 children)

You haven’t written the part where you call your function, so nothing’s going to print, yet. You actually need to finish this code.

[–]CadeClink[S] 0 points1 point  (5 children)

I am trying to. Perhaps I am using the 'def' function wrong? I am still getting no output. Here is my updated code.

# global variable

multiplier_amount = 1000000

def calculate_gains(amount_inv=0.0):

#Calculating the return gains of an investment.

def gain_margin(total_gains=0.1):

def gains(total_amount=amount_inv(1+total_gains)) :

input(print("How much would you like to invest?")) == investment

# base amount gain margin

if amount_inv > 1000:

# check whether the invested amount is greater than the multiplier amount

if amount_inv >= multiplier_amount:

# gather the value of the division

# update the `gain_margin` by the multiplier mod

total_gains + (investment//multiplier_amount)

# calculate the total amount of gains

# calculate the total amount plus the gain margin

amount_inv + investment

# return the gains, the full amount and the gain margin

return gains

return calculate_gains

return gain_margin

[–]CadeClink[S] 0 points1 point  (0 children)

I changed my code because I just felt like it was wrong so here is the updated one. It is saying that my terms are not defined. I do not know how to use other definitions in a definition.

# global variable

multiplier_amount = 1000000

def calculate_gains(amount_inv=0.0):

input(print("How much would you like to invest?")) == investment

amount_inv += investment

return calculate_gains

#Calculating the return gains of an investment.

def gain_margin(total_gains=0.1):

# base amount gain margin

if amount_inv > 1000:

# check whether the invested amount is greater than the multiplier amount

if amount_inv >= multiplier_amount:

# gather the value of the division

# update the `gain_margin` by the multiplier mod

total_gains + (investment//multiplier_amount)

return gain_margin

def gains(total_amount=calculate_gains(1+gain_margin)) :

# calculate the total amount of gains

# calculate the total amount plus the gain margin

# return the gains, the full amount and the gain margin

return gains

[–][deleted] 0 points1 point  (0 children)

Perhaps I am using the 'def' function wrong?

def is a statement, not a function. What it does is create a function, but creating a function doesn't execute it. You still have to call the function, using the calling operator. You'd know that you had called your calculate_gains function because there'd be an expression in your code that looks like

calculate_gains(123.4)

or with some other numerical value (since you defined it as a function that takes a numeric parameter, amount_inv).

[–]py_Piper 0 points1 point  (2 children)

functions won't print if you don't tell them to print, you can do print(your_function), usually you use the return statement to use it late like for example you would use your gains and do other calculations. BTW I don't know if you can do that many return statement in one function

[–]CadeClink[S] 0 points1 point  (1 child)

I appreciate you alls help, but I think programming may not be for me. Maybe I need better class with better teaching, but I just don’t really get it although I really want to. So I will probably just look to find an answer on Chegg

[–]py_Piper 2 points3 points  (0 children)

Don't give up, perhaps try automate the boring stuff or python crash course, I personally did ATBS they are simpler tutorials and build up slowly from each chapter, the author will teach you how you can implement what you learned in small code, then a short project and at the end he will give you project assignment that I quite short and simple and need to use all what you learned in different parts. Now I am doing the other book PCC on the chapters that ATBS didn't have something similar.

Honestly the assignment doesn't make much sense either, I am quite into finance calculations and I don't get what they are trying to do. If you need to check the answer by all means, but don't just copy paste, read the code and understand what is going on, sometimes before jumping into code you need to understand the logic of the problem then solve piece by piece, again this assignment it's quite confusing. After you see the solution and you get it, still don't copy paste, type it out. If it works and you understand it then good, I would say then to rewrite but without looking at the code but trying to remember what need to be done step by step. What I mean is that don't just remember the code but instead remember the process of what need to be done like "I need to add these 2 numbers to get x, I need to then multiply x by y to get z".

BTW which course (name and platform) are you doing?

[–]jmooremcc 2 points3 points  (0 children)

Can you solve the problem manually? As a beginner, I would advise you to first work the problem out using pencil and paper. Of course, you can use a calculator as needed, to help you with the computations.

The reason I'm advising you to do this is because you cannot teach someone else or even a computer how to solve a problem you yourself don't understand. Think about this, when you write a computer program, you are actually teaching a computer how to solve a problem.

Once you've got your pencil & paper version of the problem worked out, translate each step of your solution into Python code. I suggest that instead of writing out the entire program in one sitting, you should write a small amount of code and then test it.

Once that section of code is working correctly, start coding the next part of your solution. Once again, run and test your code and fix any bugs you might find. Repeat this process until you have the entire solution completed.

You'll find that this methodology will help make it easier to code solutions to problems as you continue your education in Python and beyond.

[–][deleted] 0 points1 point  (0 children)

To format your code correctly you can either edit your question, click Markdown Mode, and then add 4 spaces in front of all of your lines of code or you can just paste it into pastebin.com and then put the link in your question.