首页 > 解决方案 > “IndexError:数组索引过多” - 似乎无法修复此错误消息?

问题描述

我看过其他问题,但我不相信这些问题适用于我的情况——因为我不能推迟我需要做的事情。

总结一下有问题的代码:

import numpy as np
noInvestments=int(input("How many types of savings will you have? "))
savingTypes=[np.empty(())]
interests=np.empty(())
years=np.empty(())
contributions=np.empty(())
balance=np.empty(())


for i in range(0,noInvestments):
    totalContributions=0
    totalYears=0
    p=float(input("What is your principal? "))
    name=str(input("What is the savings type name? "))
    #save savings type into array
    savingTypes[i]=name
    interest=float(input("What is the interest? (%) "))
    #save interest into array
    interests[i]=interest
    z=1+(interest/100)

我希望能够在循环完成后拉出数组,并拥有相应的账户名称和利率。我一直在尝试不同的东西,上次我运行它时,savingTypes[i]=name 运行良好,而兴趣又出现了错误?除了它们的存储方式之外,我看不出有什么不同,而这以前没有改变过吗?

希望有人能够提供帮助!我会很感激!

标签: pythonarraysnumpyloopsvariables

解决方案


推荐阅读