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