-4

So im trying to make a chess game and im super close but i cant figure out how to select a variable to change using: ___ = input()

so heres an example

x = 1
y = 2
z = 3

variable = input()
#I would select x

and i want to be able to select what variable to change then chose the variable i want it to be equal to which even i selected.

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

so i would want 2.

Edit:

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
Censored
  • 33
  • 1
  • 1
  • 5

1 Answers1

1

I think a reasonable solution here is to change from variables x,y and z to a dictionary with keys "x", "y" and "z"; wherever your code uses x, replace that with 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)
Tom McDermott
  • 221
  • 1
  • 3