我已經開始在Python中編寫一個程序,用戶輸入他們想要向上/向下和向左/向右移動多少個空格,並且使用內置函數中的.split()來完成此操作,但是當我運行程序我得到錯誤'值錯誤:太多的值解開(兩個預期)'時,只有兩個給出。如果有人幫我解決了這個問題,將不勝感激。我重視我下面的代碼: /編輯 - 我附上所有我下面的代碼:爲什麼我得到一個值錯誤:太多的值解壓縮?
choice=0
b=0
oldP=0
newP=0
player_location=' X '
x=8
y=0
xi=0
yi=0
up=0
down=0
left=0
right=0
new_board=[xi][yi]
gold_coins=0
bandits=5
treasure_chests=10
a=1
xi2=0
yi2=0
import random
def menu():
print('If you would like to play the Treasure Hunt , press 1')
choice=input('If not, press any key to exit')
if choice=='1':
print('Great! You have made the right choice :)')
else:
print('Goodbye.')
quit()
menu()
def grid():
new_board = [ ]
def board():
new_board = [ ]
top_row = [' 1 ',' 2 ',' 3 ',' 4 ',' 5 ',' 6 ',' 7 ',' 8 ']
new_board.append(top_row)
for x in range(0,8):
row = [' 0 ']*8
new_board.append(row)
return new_board
def print_board(b):
row_numbers = [' ','1','2','3','4','5','6','7','8']
i = 0
for row in b:
print (row_numbers[i],''.join(row))
i=i+1
new_board = board()
xi=int(8)
yi=int(0)
new_board[xi][yi] = player_location
while a==1:
def get_move():
advice = 'Please enter your move in two integers, vertical, then horizontal. Use positive numbers for up and right, negative for down and left.'
example = 'For example, an input of \'22\' would be 2 moves vertically, and 2 moves horizontally.'
move = input(advice + example)
move.split()
x_move,y_move=move
x_move = int(move[0])
y_move = int(move[1])
return x_move, y_move, move
while True:
print_board(new_board)
x_move, y_move = get_move()
move(x_move, y_move) # performs the move; updates the board grid()
請向我們展示您給系統的輸入。 –
追溯或你得到不準確/猜測的答案(最終提供的解決方案,但更大,不必要的努力) –
剛剛更新我的帖子與我的其他代碼!謝謝:) – user5095215