在我開始之前,讓我說這是我第一次單獨編寫代碼,而且我對編碼還比較陌生。我現在只做了幾個星期的python。不支持的操作數類型(s) - =:'list'和'int'
所以我有一個學校項目,老師讓我們做我們想做的事情,只是我們展示了我們在學習IT之前學到的東西。我正在嘗試製作一份俄勒岡小徑的副本,並且考慮到我已經訴諸因特網,它不會太好(不是說這個網站上的人不太好)。我的代碼目前看起來是這樣的:
resources = {
"food": [10],
"energy": [100],
"distance": [2000],
"exhaustion": [0],
"hunger": [0]
}
def prompt():
print "You can eat, move, hunt, or rest."
def get_action():
return raw_input("What will you do?")
def what_do(action):
for number in resources:
print number + str(resources[number])
if action == "eat":
print "You ate. Hunger restored."
resources['hunger'] == 0
resources['food'] -= 1
if action == "hunt":
print "You went out and hunted. You found 10 food."
resources['food'] += 10
print resources['food']
if action == "move":
print "You moved 50 miles."
resources['distance'] -= 50
if action == "rest":
print "You rested. Energy restored"
resources['energy'] == 100
resources['exhaustion'] == 0
def game():
while resources['distance'] >= 0:
prompt()
action = get_action()
what_do(action)
game()
在只有一個動作運作的瞬間,而這就是rest
行動。我假設這是因爲沒有真正的運營商,它只是刪除我的疲憊回到0無論它的工作如預期,我不能說,因爲輸出保持不變。與其他所有的動作,我收到以下錯誤消息的變體:
Traceback (most recent call last):
File "python", line 46, in <module>
File "python", line 44, in game
File "python", line 27, in what_do
TypeError: unsupported operand type(s) for -=: 'list' and 'int'
是(30,如果你想知道34)中列出的第三行改變各個輸出的唯一的東西,和運營商的變化到+
。我會重申,我對編碼非常陌生,所以我不知道這意味着什麼。任何幫助表示讚賞。