' float'对象不可订阅 - 列表编码
acumSubTotal = 0
acumIva = 0
acumTotalProd = 0
listatotalProd=[]
listasubTotal = []
listacodProducto= []
listanomProducto=[]
listacanProducto=[]
listavalUnitario=[]
listatipoIva=[]
N = int(input("Digite la cantidad de Artículos a facturar: "))
for item in range(N):
i = item + 1
listacodProducto.append(int(input(f"Digite el código del producto {item + 1}: ")))
listanomProducto.append((input(f"Digite el nombre del producto {item + 1}: ")))
listacanProducto.append(float(input(f"Digite la cantidad del producto {item + 1}: ")))
listavalUnitario.append(float(input(f"Digite el valor unitario del producto {item + 1}: ")))
listatipoIva.append(float(input(f"Tipo de IVA (que puede ser: 1: Exento de IVA, 2: Bienes, IVA 5%, 3: General, IVA 19%) del producto {item + 1}: ")))
listasubTotal.append(listavalUnitario[item] * listacanProducto[item])
if listatipoIva[item] == 1:
listatipoIva = 0
elif listatipoIva[item] == 2:
listatipoIva = listasubTotal[item] * 0.05
else :
listatipoIva = listasubTotal[item] * 0.19
listatotalProd.append(listatipoIva[item] + listasubTotal[item])
我找不到这个问题的原因。我刚开始,我无法弄清楚什么是错误。西班牙语中的代码希望您不介意。帮助!!
该错误是在“ float”对象下的最后一行上特别显示的错误。
acumSubTotal = 0
acumIva = 0
acumTotalProd = 0
listatotalProd=[]
listasubTotal = []
listacodProducto= []
listanomProducto=[]
listacanProducto=[]
listavalUnitario=[]
listatipoIva=[]
N = int(input("Digite la cantidad de Artículos a facturar: "))
for item in range(N):
i = item + 1
listacodProducto.append(int(input(f"Digite el código del producto {item + 1}: ")))
listanomProducto.append((input(f"Digite el nombre del producto {item + 1}: ")))
listacanProducto.append(float(input(f"Digite la cantidad del producto {item + 1}: ")))
listavalUnitario.append(float(input(f"Digite el valor unitario del producto {item + 1}: ")))
listatipoIva.append(float(input(f"Tipo de IVA (que puede ser: 1: Exento de IVA, 2: Bienes, IVA 5%, 3: General, IVA 19%) del producto {item + 1}: ")))
listasubTotal.append(listavalUnitario[item] * listacanProducto[item])
if listatipoIva[item] == 1:
listatipoIva = 0
elif listatipoIva[item] == 2:
listatipoIva = listasubTotal[item] * 0.05
else :
listatipoIva = listasubTotal[item] * 0.19
listatotalProd.append(listatipoIva[item] + listasubTotal[item])
I cannot find a reason for this problem. I'm just getting started and I can't figure out what is the error. Code's in spanish hope you don't mind. Help!!
The error is showing specifically on the last line under 'float' object is not subscriptable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正在执行的列表中
问题在于,您将
listatipoiva
定义为列表,然后在您尝试访问listatipoiva [item]
的结尾时 循环您看到的错误是因为ListAtipoiva不再是可订阅的对象。可订阅的对象是实现
__ getItem __()
方法的对象,例如:字符串,列表,元组和词典。不是漂浮或ints。您需要研究这种结构:
并弄清楚您想做什么。如果我正确理解,则根据所选用户输入(1、2或3),您要在
listAsubtotal
值上操作。也许您正在寻找类似的东西:它将根据所选的IVA选项更改ListAsubtotal [item]的值。
作为建议,要改善代码可读性,请使用snake_case或如果您真的想使用骆驼箱一致使用(
listAcanAcanProducto
而不是listAcanProducto
)The problem is that you are defining
listatipoIva
as a list but then in you if-statement you are doingWhen you try to access
listatipoIva[item]
at the end of you for loop the error you are seeing is because listatipoIva is no longer a subscriptable object.Subscriptable objects are those that implement the
__getitem__()
method like: strings, lists, tuples, and dictionaries. NOT floats or ints.You need to look into this structure:
And figure out what you want to do. If I understand right, depending on the selected user input (1, 2 or 3) you want to operate on the
listasubTotal
value. Maybe you are looking for something like this:That will change the value of listasubTotal[item] depending on the selected IVA option.
As a recommendation, to improve code readability use snake_case or if you really want to use camelCase use it consistently (
listaCanProducto
instead oflistacanProducto
)