python - “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 运行良好,而兴趣又出现了错误?除了它们的存储方式之外,我看不出有什么不同,而这以前没有改变过吗?
希望有人能够提供帮助!我会很感激!
解决方案
推荐阅读
- android - 使用 ItextPdf 创建文件 Pdf 后如何解决错误
- python - 如何将股票价格的熊猫数据框附加/连接到一个大数据框中
- mysql - 如何在 SQL Server 2012 的单个查询中使用更改表列并添加约束
- sql-server - SQLServer 生成日期到两个日期之间的行
- python - 在多个服务器上使用 post_save 信号触发 Django 管理命令
- matlab - matlab中的函数句柄
- xamarin.forms - 如何在 Xamarin Forms 中动态设置 ListView 的 RowHeight
- php - 从日光开始之前保存的偏移量获取当前时区偏移量
- python - Python tkinter 包无法正常运行
- sharepoint - 如何在 Pega 的共享点中创建文件夹时设置元数据(cmis:名称和 cmis:描述)