Other option is to make a dictionary,can just use your code and add
Also showing
dict()
.Also showing
f-string
so can avoid code like "line_" + str(line)
.# Make dictionary line_record = dict( Line_1 = "Choice_C", Line_2 = "Choice_B", Line_3 = "Choice_A", ) line = input("pick a line number: ") result = line_record.get(line, 'No record of that input') print(result) print('--------------') # Example of f-string print(f'Input was <{line}> with result of <{result}>')
Output:λ python line_code.py
pick a line number: Line_2
Choice_B
--------------
Input was <Line_2> with result of <Choice_B>
λ python line_code.py
pick a line number: Line1000
No record of that input
--------------
Input was <Line1000> with result of <No record of that input>