0

n 是变量,但在这种情况下,customer[n]["amount"] = 300 并不重要,但是当我尝试添加 400 时,结果显示为 300400。我需要帮助。提前感谢任何帮助我的人。

textwindow.writeline("How much do you want to add?")
adding = TextWindow.ReadNumber()
trying to reassign the string customer[n]["amount"]
customer[n]["amount"] = customer[n]["amount"] + adding
TextWindow.WriteLine("Your new amount is: " + customer[n]["amount"])
4

2 回答 2

1

您必须将数字转换为整数,请尝试以下操作:

customer[n]["amount"] = customer[n]["amount"]*1 + adding*1
于 2015-04-08T09:54:41.590 回答
0

问题一定出在程序的其余部分。我刚刚在这里运行了这个程序,没有任何问题

n = 1
customer[n]["amount"] = 300
textwindow.writeline("How much do you want to add?") 
adding = TextWindow.ReadNumber()
customer[n]["amount"] = customer[n]["amount"] + adding
TextWindow.WriteLine("Your new amount is: " + customer[n]["amount"])

在程序的其他地方,您必须将金额定义为文本。然后结果将作为附加的两个文本出现。就像“Jelly”+“Jam”出来的“JellyJam”

于 2015-04-08T01:29:56.667 回答