如何在不复制最后一个输入的情况下打印代码?
N = int(input("Digite la cantidad de Artículos a facturar: "))
dataProd = ('Código', 'Nombre', 'Cantidad', 'Valor unitario', 'Tipo de IVA')
listdataProd = []
compra = {}
acuSubTotal= 0
acuIvatotal= 0
acuTotalprod= 0
for item in range(N):
listdataProd = []
for dato in dataProd:
listdataProd.append(input(f"Digite el {dato} del producto {item + 1}: "))
compra[item+1] = listdataProd
compra[item+1].append(int(compra[item+1][2]) * int(compra[item+1][3]))
iva = (0, 0.05, 0.19)
if int(compra[item+1][4]) == 1:
compra[item+1].append(float(compra[item+1][5]) * iva[0])
elif int(compra[item+1][4]) == 2:
compra[item+1].append(float(compra[item+1][5]) * iva[1])
else:
compra[item+1].append(float(compra[item+1][5]) * iva[2])
compra[item+1].append(int(compra[item+1][5]) + int(compra[item+1][6]))
acuSubTotal += compra[item+1][5]
acuIvatotal += compra[item+1][6]
acuTotalprod += compra[item+1][7]
print("\n****************")
print("Detalles de la compra: ")
print("****************")
for i in range(N):
print(f"\nCodigo del Producto {i + 1}: ", compra[item+1][0])
print(f"Nombre del Producto {i + 1}: ", compra[item+1][1])
print(f"Cantidad del Producto {i + 1}: ", compra[item+1][2])
print(f"Valor Unitario del Producto {i + 1}: ", compra[item+1][3])
print(f"Tipo de Iva del Producto {i + 1}: ", compra[item+1][4])
print(f"Subtotal del Producto {i + 1}: ", compra[item+1][5])
print(f"Iva del Producto {i + 1}: ", compra[item+1][6])
print(f"Valor Total del Producto {i + 1}: ", compra[item+1][7])
print("\n****************")
print("Totales de la compra: ")
print("****************")
print("SubTotal de la compra: ", acuSubTotal)
print("IVA Total de la compra: ", acuIvatotal)
print("Total de la compra: ", acuTotalprod)
你好!我刚刚开始在编码世界上,现在我有点泡菜了。当我打印出传出信息时,仅显示了最后要求的n次输入,在代码末尾,数学汇总了,因此我可以肯定的是,所有信息都在字典中,但它只是未正确打印!我正在读你们!谢谢!!
N = int(input("Digite la cantidad de Artículos a facturar: "))
dataProd = ('Código', 'Nombre', 'Cantidad', 'Valor unitario', 'Tipo de IVA')
listdataProd = []
compra = {}
acuSubTotal= 0
acuIvatotal= 0
acuTotalprod= 0
for item in range(N):
listdataProd = []
for dato in dataProd:
listdataProd.append(input(f"Digite el {dato} del producto {item + 1}: "))
compra[item+1] = listdataProd
compra[item+1].append(int(compra[item+1][2]) * int(compra[item+1][3]))
iva = (0, 0.05, 0.19)
if int(compra[item+1][4]) == 1:
compra[item+1].append(float(compra[item+1][5]) * iva[0])
elif int(compra[item+1][4]) == 2:
compra[item+1].append(float(compra[item+1][5]) * iva[1])
else:
compra[item+1].append(float(compra[item+1][5]) * iva[2])
compra[item+1].append(int(compra[item+1][5]) + int(compra[item+1][6]))
acuSubTotal += compra[item+1][5]
acuIvatotal += compra[item+1][6]
acuTotalprod += compra[item+1][7]
print("\n****************")
print("Detalles de la compra: ")
print("****************")
for i in range(N):
print(f"\nCodigo del Producto {i + 1}: ", compra[item+1][0])
print(f"Nombre del Producto {i + 1}: ", compra[item+1][1])
print(f"Cantidad del Producto {i + 1}: ", compra[item+1][2])
print(f"Valor Unitario del Producto {i + 1}: ", compra[item+1][3])
print(f"Tipo de Iva del Producto {i + 1}: ", compra[item+1][4])
print(f"Subtotal del Producto {i + 1}: ", compra[item+1][5])
print(f"Iva del Producto {i + 1}: ", compra[item+1][6])
print(f"Valor Total del Producto {i + 1}: ", compra[item+1][7])
print("\n****************")
print("Totales de la compra: ")
print("****************")
print("SubTotal de la compra: ", acuSubTotal)
print("IVA Total de la compra: ", acuIvatotal)
print("Total de la compra: ", acuTotalprod)
Hi! Im just getting started on the coding world and now I'm in a bit a pickle. When I print the outgoing information is only showing the last input requested N times, at the end of the code the math is adding up, so I know for sure all the information is in the dictionary but it is just not properly printing! I'm reading you guys! Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该修复代码中的一些凹痕,所有产品输入都应进入循环内部。如果仅想要总和(最后3行),则可以删除所有8
print
语句循环中的语句:示例运行:
You should fix some indentations in the code and all the product inputs should go inside the loop. If you want only the total sum (last 3 lines), you can remove all 8
print
statements inside the loop:Example run: