我已经减少了代码,只显示了我认为与以下错误相关的部分。这是在python 3.x中完成的,因为我正在尝试自学,所以我没有任何python 2.x的经验
谢谢!
Traceback (most recent call last):
File "rpcombat_refactored.py", line 306, in <module> shopping = buy_equipment()
File "rpcombat_refactored.py", line 242, in buy_equipment
print("You have a", join_with_and(profile['inventory']), "in your bag.")
File "rpcombat_refactored.py", line 94, in join_with_and elif sequence < 1:
TypeError: unorderable types: list() < int()
代码:
def join_with_and(sequence):
if len(sequence) > 1:
last_item = sequence[-1]
sentence = ", ".join(sequence[:-1])
sentence = sentence + " and " + last_item
elif sequence < 1:
sentence = "whole lot of nothing"
else:
sentence = sequence[0]
return sentence
def buy_equipment():
# Omitting item list
# Omitting purchase prompt
# If the item is in stock and the player has enough gold, buy it
if purchase in stock:
if stock[purchase][0] <= profile['gold']:
test_phrase = profile['Name'] + " buys themself some equipment"
print(fix_gender(profile['Gender'],test_phrase))
print("You buy a", purchase, "for", stock[purchase][0], "gold pieces.")
profile['gold'] -= stock[purchase][0]
profile['inventory'].append(purchase)
print("You have a", join_with_and(profile['inventory']), "in your bag.")
print("You have", profile['gold'], "left.")
else:
print("You don't have enough gold to buy that.")
elif purchase == 'done' or purchase == "":
return profile['inventory'] == [] and profile['gold'] > 10
else:
print("We don't have", purchase, "in stock.")
return purchase
答案 0 :(得分:1)
您的generate_rpc
方法未返回个人资料。它什么都不返回。所以profile
是无。