我如何...让我的代码返回n [英] How do i...get my code to return n

查看:79
本文介绍了我如何...让我的代码返回n的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它假设要返回n但它没有帮助请求



我尝试过:



ef pay_off_period(PV,PMT,i):

年= 0

n =年

投资= 0

FV = 0

而FV< = PV:

interest = FV *(i)

FV + =兴趣

FV + = PMT

年= + 1

#investment = round(FV /(1 + i)** n, 1)



返回int(n)

it suppose to return n but it doesnt help pleas

What I have tried:

ef pay_off_period(PV, PMT, i):
years = 0
n = years
investment = 0
FV = 0
while FV <= PV:
interest = FV*(i)
FV += interest
FV += PMT
years =+1
#investment =round(FV/(1 + i)**n,1)

return int(n)

推荐答案

您需要将该代码转换为可调用模块。请参见 6。模块 - Python 3.4.9文档 [ ^ ]。
You need to make that code into a callable module. See 6. Modules — Python 3.4.9 documentation[^].


你的意思是

Do you mean
def pay_off_period(PV, PMT, i):
  years = 0
  FV = 0
  while FV <= PV:
    interest = FV*(i)
    FV += interest
    FV += PMT
    years += 1
  return years


def pay_off_period(PV,PMT,i):

n = 0



while 0< PV:

PV = PV *(1 + i) - PMT

n + = 1



return( n)

打印(pay_off_period(1578934,15000 * 12,0.1045))
def pay_off_period(PV, PMT, i):
n = 0

while 0 < PV:
PV = PV * (1+i) - PMT
n += 1

return(n)
print(pay_off_period(1578934, 15000*12, 0.1045))


这篇关于我如何...让我的代码返回n的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆