Embedded function returns None

2024/7/7 6:43:53

My function returns None. I have checked to make sure all the operations are correct, and that I have a return statement for each function.

def parameter_function(principal, annual_interest_rate, duration):n = float(duration * 12)if annual_interest_rate == 0:r = float(principal / n)else:r = float(annual_interest_rate / 1200)p = principalreturn (p, r, n)def monthly_payment_function(p, r, n):monthly_payment = p * ((r * ((1 + r) ** n)) / (((1 + r) ** n) - 1))result = monthly_payment_function(p, r, n)return result
Answer

monthly_payment_function does not return anything. Replace monthly_payment= with return (that's 'return' followed by a space).

Also you have an unconditional return before def monthly_payment_function, meaning it never gets called (strictly speaking, it never even gets defined).

Also you are pretty randomly mixing units, and your variable names could use some help:

from __future__ import division    # Python 2.x: int/int gives floatMONTHS_PER_YEAR = 12def monthly_payment(principal, pct_per_year, years):months = years * MONTHS_PER_YEARif pct_per_year == 0:return principal / monthselse:rate_per_year   = pct_per_year / 100.rate_per_month  = rate_per_year / MONTHS_PER_YEARrate_compounded = (1. + rate_per_month) ** months - 1.return principal * rate_per_month * (1. + rate_compounded) / rate_compounded
https://en.xdnf.cn/q/120218.html

Related Q&A

calculate days between several dates in python

I have a file with a thousand lines. Theres 12 different dates in a single row. Im looking for two conditions. First: It should analyze row by row. For every row, it should check only for the dates bet…

Appeding different list values to dictionary in python

I have three lists containing different pattern of values. This should append specific values only inside a single dictionary based on some if condition.I have tried the following way to do so but i go…

Split only part of list in python

I have a list[Paris, 458 boulevard Saint-Germain, Marseille, 29 rue Camille Desmoulins, Marseille, 1 chemin des Aubagnens]i want split after keyword "boulevard, rue, chemin" like in output[Sa…

How to find the index of the element in a list that first appears in another given list?

a = [3, 4, 2, 1, 7, 6, 5] b = [4, 6]The answer should be 1. Because in a, 4 appears first in list b, and its index is 1.The question is that is there any fast code in python to achieve this?PS: Actual…

How to yield fragment URLs in scrapy using Selenium?

from my poor knowledge about webscraping Ive come about to find a very complex issue for me, that I will try to explain the best I can (hence Im opened to suggestions or edits in my post).I started usi…

Django Database Migration

Hi have a django project a full project now I want to migrate to mysql from the default Sqlite3 which is the default database. I am on a Mac OS and I dont know how to achieve this process. Any one wit…

Search engine using python for bookmarked sites [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 1…

How to extract only particular set of structs from a file between braces in python

a. Have a scenario, where in my function reads in a file which contains list of c-structures as shown below, reads the file and extracts all the information between { } braces for each structure and st…

Selection of Face of a STL by Face Normal value Threshold

I want to write a script in Python which can generate facegroups in a STL as per the Face Normal value condition. For example, Provided is the snap of Stl, Different colour signifies the face group con…

Python , Changing a font size of a string variable

I have a variable that gets sent to a email as text but the text is all pretty much a standard size with everything the same. I would like to add some emphasis to it as well as make it bigger and make …