【问题标题】:Need help in python lists在 python 列表中需要帮助
【发布时间】:2023-01-26 21:59:40
【问题描述】:

我是一个编码新手,在创建这个程序时我有一个想法

Q- 制作一个程序,你可以看到将钱存入银行的人在 1 年后获得的金额,利息为 12%,并计算 1 年支付的总利息

答-

balance= [12000,10000,33000,55000]

total= 0

for i in balance :

    intst= i*12*1/100

    total= total + intst

    print("intres of",i,"=",intst)

print("total intrest paid by the bank in 1 year =",total)

我想知道我是否可以指定将钱存入其中的人的姓名,当它打印时它会显示为 xxxx deposited 12000 = 1440.0

如果这听起来太复杂或太愚蠢,我很抱歉,我真的很想知道这是否可能

我尝试使用字典,但失败了 lmao

【问题讨论】:

  • 欢迎来到堆栈溢出。请带上tour阅读How to Ask,注意这是不是论坛.请仔细思考代码,再想到具体的问题它。不要谈论你自己。相反,直接解释:1)你想要代码做什么? 2)代码是什么? 3) 当您尝试该代码时会发生什么? 4) 这与您想要的有何不同? 5)你的问题是什么关于这个区别?
  • 我们无法为您设计程序功能。确保你知道究竟是什么在编写代码之前,您希望代码执行此操作。

标签: python list dictionary


【解决方案1】:

字典可以使用格式 {"Name" : 1000} # 1000 是存款金额

interest_rate = 0.12
balances = {
    "John": 12000,
    "Joseph": 10000,
    "Joline": 33000,
    "Jose": 55000
}
interests = []
for name in balances:
    deposit = balances[name]
    interest = deposit * interest_rate
    print(f"{name} deposited {deposit}, after one year, the interest was {interest}")

输出:

John deposited 12000, after one year, the interest was 1440.0
Joseph deposited 10000, after one year, the interest was 1200.0
Joline deposited 33000, after one year, the interest was 3960.0
Jose deposited 55000, after one year, the interest was 6600.0

【讨论】:

    猜你喜欢
    • 2010-09-29
    • 1970-01-01
    • 1970-01-01
    • 2014-11-04
    • 2020-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多