1
我正在寫一個簡單的程序來幫助爲我參加的遊戲生成訂單。它屬於我實際上並不需要的節目的目標。但現在我已經開始了,我希望它能夠工作。這一切都運行得很順利,但我無法弄清楚如何在一半的時間內停止類型錯誤。這是代碼;Python類型錯誤問題
status = 1
print "[b][u]magic[/u][/b]"
while status == 1:
print " "
print "would you like to:"
print " "
print "1) add another spell"
print "2) end"
print " "
choice = input("Choose your option: ")
print " "
if choice == 1:
name = raw_input("What is the spell called?")
level = raw_input("What level of the spell are you trying to research?")
print "What tier is the spell: "
print " "
print "1) low"
print "2) mid"
print "3) high"
print " "
tier = input("Choose your option: ")
if tier == 1:
materials = 1 + (level * 1)
rp = 10 + (level * 5)
elif tier == 2:
materials = 2 + (level * 1.5)
rp = 10 + (level * 15)
elif tier == 3:
materials = 5 + (level * 2)
rp = 60 + (level * 40)
print "research ", name, "to level ", level, "--- material cost = ",
materials, "and research point cost =", rp
elif choice == 2:
status = 0
任何人都可以幫忙嗎?
編輯
我得到的是錯誤;
Traceback (most recent call last):
File "C:\Users\Mike\Documents\python\magic orders", line 27, in <module>
materials = 1 + (level * 1)
TypeError: unsupported operand type(s) for +: 'int' and 'str'
你能發佈實際的錯誤嗎?我猜你最終使用一個字符串作爲整數的地方。 – Draemon 2008-11-26 14:21:17
男孩,這是不好的代碼... – hop 2008-11-27 12:34:27