![](/img/trans.png)
[英]Python: TypeError: 'int' object does not support item assignment for MinMaxScaler
[英]TypeError: 'int' object does not support item assignment Python
誰能告訴我為什么我在 Python 2.7 中不斷收到此錯誤,請參閱下面的錯誤標記。 提前致謝!
我必須制作一個程序來計算每個人的硬幣數量並計算出他們的總數
TotalPeople = int(raw_input("Enter the number of people "))
Loop = 0
DC2 = 0
DC1 = 0
C50 = 0
C25 = 0
C10 = 0
C5 = 0
C2 = 0
TVC = 0.0
i = 1
while i != TotalPeople:
DC2[i] = raw_input("How many 2 dollar coins?") // ERROR for this line
DC1[i] = raw_input("How many 1 dollar coins?")
C50[i] = raw_input("How many 50 cent coins?")
C25[i] = raw_input("How many 25 cent coins?")
C10[i] = raw_input("How many 10 cent coins?")
C5[i] = raw_input("How many 5 cent coins?")
C2[i] = raw_input("How many 2 cent coins?")
Total = (DC2[i] *2) + (DC1[i] * 1) + (C50[i] * 0.50) + (C25[i] * 0.25) + (C10[i] * 0.10) + (C5[i] * 0.05) + (C2[i] * 0.02)
print "The total is " + Total
iw = 1
while iw != TotalPeople:
TVC = TVC + (DC2[iw] * 2)
TVC = TVC + (DC1[iw] * 1)
TVC = TVC + (C50[iw] * 0.50)
TVC = TVC + (C25[iw] * 0.25)
TVC = TVC + (C10[iw] * 0.10)
TVC = TVC + (C5[iw] * 0.05)
TVC = TVC + (C2[iw] * 0.02)
print("The total value is CAD $" + str(TVC) + " for " + str(TotalPeople) + " people")
您已將 DC 聲明為整數,但在此行中:
DC2[i] = raw_input("How many 2 dollar coins?")
(以及前面的所有連續行),您正在處理它,就好像它是一個可描述的對象。 我認為你想要的是擺脫你在 while 循環中所做的所有索引分配。
DC2 = raw_input("How many 2 dollar coins?")
DC1 = raw_input("How many 1 dollar coins?")
C50 = raw_input("How many 50 cent coins?")
C25 = raw_input("How many 25 cent coins?")
C10 = raw_input("How many 10 cent coins?")
C5 = raw_input("How many 5 cent coins?")
C2 = raw_input("How many 2 cent coins?")
DC2
是一個整數。 您試圖將它分配給它,就好像它是一個list
(帶有索引)。 那行不通。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.