Why does my code not return anything

后端 未结 5 1546
终归单人心
终归单人心 2021-01-29 16:28

fairly new to programming and trying to learn Python at the moment. I have this code and I don\'t understand why I don\'t get a return value :(

balance = 3200
an         


        
5条回答
  •  春和景丽
    2021-01-29 17:17

    You're being unclear about what function you expect to return a value, but as I cannot comment and prod yet I'll provide a possible answer.

    First of all, in this code you never actually call any of the functions. I'm assuming this is done elsewhere.

    As for f(x), there's no return value because you have not made a Return statement. I would also refrain from using variables as Globals, it's typically bad practice. Instead, if you want to modify MonthlyInterestRate send it as a parameter to f() and return the new value.

    bisection only returns if f(c) == 0 but f() does not have a Return statement, so that will never happen. Past that, once it exits the loop it will only print c so no return value there either.

    If you want to compare a function, it NEEDS a Returnstatement.

提交回复
热议问题