0

I have a code written in python and I want to get a number from user and then add a 'c' character before that and then find that variable. But I just get the string. Here is my code using dictionary:

c1234 = {"name":"Komeil", "family":"Asadollah Nia"}

codee = int (input ("Please enter your code: "))
code = "c" + str(codee)

print (code)

I want to get my dictionary but it just prints "c1234"

Please help me.

  • you can assign code = c1234 – Samsul Islam Apr 17 '21 at 11:35
  • If `'c1234'` is the name of a global variable, the variable's value _could_ be referenced via `globals()[code]`, however doing so is considered a very poor programming practice and a security hazard. A simple alternative is to use a dictionary as suggested in the accepted answer to the duplicate question (and redundantly in @Green's [answer](https://stackoverflow.com/a/67137709/355230) below). – martineau Apr 17 '21 at 12:38

0 Answers0