2017-01-18 61 views
-4

所以我試着做一盤棋和IM超近,但我不能弄清楚如何選擇一個變量使用改變: ___ =輸入()Python的國際象棋項目

所以下面有一個例子

x = 1 
y = 2 
z = 3 

variable = input() 
#I would select x 

我希望能夠選擇要更改的變量,然後選擇我希望它等於哪個變量的變量。

variable1 = input() 
#I would select y 
variable = variable1 

,所以我想2.

編輯:

a1 = "♖" 
a2 = "♙" 
a3 = " " 
a4 = " " 
a5 = " " 
a6 = " " 
a7 = "♟" 
a8 = "♜" 

b1 = "♘" 
b2 = "♙" 
b3 = " " 
b4 = " " 
b5 = " " 
b6 = " " 
b7 = "♟" 
b8 = "♞" 

c1 = "♗" 
c2 = "♙" 
c3 = " " 
c4 = " " 
c5 = " " 
c6 = " " 
c7 = "♟" 
c8 = "♝" 

d1 = "♔" 
d2 = "♙" 
d3 = " " 
d4 = " " 
d5 = " " 
d6 = " " 
d7 = "♟" 
d8 = "♚" 

e1 = "♕" 
e2 = "♙" 
e3 = " " 
e4 = " " 
e5 = " " 
e6 = " " 
e7 = "♟" 
e8 = "♛" 

f1 = "♗" 
f2 = "♙" 
f3 = " " 
f4 = " " 
f5 = " " 
f6 = " " 
f7 = "♟" 
f8 = "♝" 

g1 = "♘" 
g2 = "♙" 
g3 = " " 
g4 = " " 
g5 = " " 
g6 = " " 
g7 = "♟" 
g8 = "♞" 

h1 = "♖" 
h2 = "♙" 
h3 = " " 
h4 = " " 
h5 = " " 
h6 = " " 
h7 = "♟" 
h8 = "♜" 
space = " " 

while True: 
    print("h ┼" + h1 + "┼" + h2 + "┼" + h3 + "┼" + h4 + "┼" + h5 + "┼" + h6 + "┼" + h7 + "┼" + h8 + "┼") 
    print("g ┼" + g1 + "┼" + g2 + "┼" + g3 + "┼" + g4 + "┼" + g5 + "┼" + g6 + "┼" + g7 + "┼" + g8 + "┼") 
    print("f ┼" + f1 + "┼" + f2 + "┼" + f3 + "┼" + f4 + "┼" + f5 + "┼" + f6 + "┼" + f7 + "┼" + f8 + "┼") 
    print("e ┼" + e1 + "┼" + e2 + "┼" + e3 + "┼" + e4 + "┼" + e5 + "┼" + e6 + "┼" + e7 + "┼" + e8 + "┼") 
    print("d ┼" + d1 + "┼" + d2 + "┼" + d3 + "┼" + d4 + "┼" + d5 + "┼" + d6 + "┼" + d7 + "┼" + d8 + "┼") 
    print("c ┼" + c1 + "┼" + c2 + "┼" + c3 + "┼" + c4 + "┼" + c5 + "┼" + c6 + "┼" + c7 + "┼" + c8 + "┼") 
    print("b ┼" + b1 + "┼" + b2 + "┼" + b3 + "┼" + b4 + "┼" + b5 + "┼" + b6 + "┼" + b7 + "┼" + b8 + "┼") 
    print("a ┼" + a1 + "┼" + a2 + "┼" + a3 + "┼" + a4 + "┼" + a5 + "┼" + a6 + "┼" + a7 + "┼" + a8 + "┼") 
    print(" 1 2 3 4 5 6 7 8") 


    print("What piece?") 
    pieceplace = input() 
    print(pieceplace) 
    print("Where to?") 
    pieceplaceloc = input() 
    print(pieceplaceloc) 
    pieceplaceloc = pieceplace 
    continue 
+0

不清楚你在問什麼。你能詳細說一下嗎? –

+0

這是python2.7還是python 3? – TemporalWolf

+0

python 3也沒有別的,我可以詳細說明。這正是我所需要的 – Censored

回答

1

我覺得這裏一個合理的解決方案是從變量x,y和z改變與鍵 「X」 的字典,「y」和「z」;無論您的代碼使用的是x,請用vars['x']替換。

vars = {} 
vars['x'] = 1 
vars['y'] = 2 
vars['z'] = 3 

variable_name = input("select variable to change: ") 

vars[variable_name] = 99 

print(vars)