| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1735 人关注过本帖
标题:萌新求教...请问我的python代码语法哪里出了问题?
只看楼主 加入收藏
timeofmei
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2020-3-4
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:3 
萌新求教...请问我的python代码语法哪里出了问题?
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()
搜索更多相关主题的帖子: value if the 语法 input 
2020-03-04 18:06
timeofmei
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2020-3-4
收藏
得分:0 
标点符号都没有问题,都检查过了
2020-03-04 18:07
Kittt
Rank: 2
等 级:论坛游民
帖 子:1
专家分:20
注 册:2020-3-5
收藏
得分:20 
函数中第一个判断的print()函数,少了括号收尾……
正确应该是:
print('{} euqals to {}'.format(x, pow(fv/pv, 1/t)-1))
2020-03-05 12:57
timeofmei
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2020-3-4
收藏
得分:0 
回复 3楼 Kittt
谢谢你,问题解决了!
2020-03-05 17:51
快速回复:萌新求教...请问我的python代码语法哪里出了问题?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015174 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved