I have a program in Python 2.7 where I'm trying to refer to some variable based on a number a user inputs. I have the following:
p1 = "foo1"
p2 = "foo2"
p3 = "foo3"
p4 = "foo4"
p5 = "foo5"
p6 = "foo6"
p7 = "foo7"
k = raw_input('Enter number')
Clearly, having if
statements on k
would be redundant. Is there a more elegant way for my program to, given k
, refer to the variable pk
? For example, if k=2
, the program would find variable p2
.