【发布时间】:2019-08-10 12:07:33
【问题描述】:
我是 python 新手,我必须运行一个程序来根据用户输入获取正确的利率,并使用获得的利率来计算每月赚取的利息。
为了计算所赚取的利息,我正在尝试使用打印结果来创建计算每月所赚取利息的公式。但是,我已经尝试了很多东西,但我不知道如何纠正这个问题。
transaction_category = [2000, 2500, 5000, 15000, 30000]
first_50k_1_category_rates = [0.05, 1.55, 1.85, 1.90, 2.00, 2.08]
if (count == 1) and (account_balance <= 50000) and (total_eligible_monthly_transactions < transaction_category[0]):
print(f'Interest rate applicable is: {first_50k_1_category_rates[0]: .2f}%')
if (count == 1) and (account_balance <= 50000) and (transaction_category[0] <= total_eligible_monthly_transactions < transaction_category[1]):
print(f'Interest rate applicable is: {first_50k_1_category_rates[1]: .2f}%')
【问题讨论】:
-
也许重新思考一下逻辑,
if语句应该选择一个计算,对吧?print的调用只是为您提供有关正在发生的事情的信息 - 它应该与我建议的逻辑或数学无关。 -
是的,if 语句将给出我应该用来计算每月赚取利息的利率。只是不确定如何使用公式中的输出来计算所赚取的利息。
-
输出是什么意思?
print和if语句都没有输出(尽管我认为print实际上返回none)。 -
获取费率时的输出,即 first_50k_1_category_rates 或 first_50k_2_categories_or_more_rates
-
if没有result(或者更确切地说是value),因为它是一个流控制statement ,也就是自成一头的野兽。 ፨ ፨所以不,您不能将if的result 用于equation(我会说,assignment statement)。另一方面,if后面的代码块可以包含任意数量的赋值,并且您可以稍后使用与名称绑定的值。有关示例,请参见 tripleee's answer。
标签: python