1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-03-25 11:12:22 +08:00
SpaceVim/test.py
Shidong Wang 4ae4cad290 Fix defx
2019-04-03 22:01:31 +08:00

27 lines
600 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import io
import sys
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
def pv_f(c, r, n, when=1):
import numpy as np #导入numpy库
c = np.array(c)
r = np.array(r)
if when == 1:
n = np.arange(1, n + 1)
else:
n = np.arange(0, n)
pv = c / (1 + r)**n
return pv.sum()
c = 20000
r = 0.05
n = 5
#调用前文定义的函数pv_f(c,r,n,when=1)
pv1 = pv_f(c, r, n, when=1)
print("普通年金现值(年末):%.2f" % pv1)
#如果是预付年金则when=0
pv2 = pv_f(c, r, n, when=0)
print("预付年金现值(年初):%.2f" % pv2)