注册 登录
编程论坛 Python论坛

萌新求教...请问我的python代码语法哪里出了问题?

timeofmei 发布于 2020-03-04 18:06, 1842 次点击
import math
def loan_calc():
    x = input('What are you gonna calculate? ')
    if x == 'r' or x == 'R':
        t = input('How long is the period in years? ')
        pv = input('What is the present value? ')
        fv = input('What is the future value? ')
        print('{} euqals to {}'.format(x, pow(fv/pv, 1/t)-1)
    if x == 'p' or x == 'P':      (这一行总是提示语法出错,如果删除的话就提示下一个if行语法出错)
        r = input('What is the interest rate? ')
        pv = input('What is the present value? ')
        fv = input('What is the future value? ')
        print('{} euqals to {}'.format(x, log(1+r, fv/pv)))
    if x == 'pv' or x == 'PV':
        r = input('What is the interest rate? ')
        t = input('How long is the period in years? ')
        fv = input('What is the future value? ')
        print('{} equals to {}'.format(x, fv/pow(1+r, t)))
    if x == 'fv' or x == 'FV':
        r = input('What is the interest rate? ')
        t = input('How long is the period in years? ')
        pv = input('What is the present value? ')
        print('{} equals to {}'.format(x, pv*pow(1+r, t)))
loan_clac()
3 回复
#2
timeofmei2020-03-04 18:07
标点符号都没有问题,都检查过了
#3
Kittt2020-03-05 12:57
函数中第一个判断的print()函数,少了括号收尾……
正确应该是:
print('{} euqals to {}'.format(x, pow(fv/pv, 1/t)-1))
#4
timeofmei2020-03-05 17:51
回复 3楼 Kittt
谢谢你,问题解决了!
1