I am creating a simple Boxing sim engine and have got things working fairly well. A few months ago I was instructed to avoid copy and pasting code and to try and "conserve my logic".
Anyways, I feel I have done a fairly good job overall but there is one area (posted below) that I feel definitely has room for improvement:
print ("1)Joe Smith\n2)Mike Jones\n3)Steve Roberts\n")
boxer1 = input("Choose a fighter: ")
boxer2 = input ("Choose his opponent: ")
if boxer1 == '1':
B1 = JS
elif boxer1 == '2':
B1 = MJ
elif boxer1 == '3':
B1 = SR
if boxer2 == '1':
B2 = JS
elif boxer2 == '2':
B2 = MJ
elif boxer2 == '3':
B2 = SR
MJ
, JS
, and SR
are all variables for objects in my Boxer class. My concern is that I will have to continue adding four lines of code for each boxer I add to the program. While I don't mind typing each line out, I realize there may be a much more efficient way to approach this that I'm not seeing. I realize this isn't a major issue but, as I mentioned, this program is mainly for practice and therefore I want to make sure I'm programming as efficiently as possible.