输入后我的代码输出的建议坐标,但我不知道如何根据第一个输出输出,所以说有人输入B4,程序建议用户输入B3,B5,A4或C4这些建议我需要它来打印第三个和最后一个建议而不使用一堆if语句。如果Attack1 ==“A1”且Attack2 ==“A2”,则为ex: print(“最后一击是A3”+ Rank +“”+ Name +“。”)
Rank= input("What is your rank?")
Name= input("What is your name " + Rank + "?")
grid= input("What would you like the length of your grid to be " + Rank + " " + Name + "?")
Attack1=input("Where do you want to attack first " + Rank + " " + Name + "?\n" +"(Please print with capital letters)")
grid= int(grid)
#Removing the Number from the Letter
RemoveNum = Attack1[0].upper()
#Removing the letter from the coordinates
RemoveLetter = Attack1[1].upper()
RemoveLett=int(RemoveLetter)
row = "1 2 3 4 5 6 7 8 9 10".split()
col = "A B C D E F G H I J".split()
x=col.index(RemoveNum)
y=row.index(RemoveLetter)
possibles=[] # blank list to store suggestions in
if x > 0 :
possibles.append(col[x-1] + row[y]) # left
if x < grid-1:
possibles.append(col[x+1] + row[y]) # right
if y > 0 :
possibles.append(col[x] + row[y-1]) # up
if y < grid-1:
possibles.append(col[x] + row[y+1]) # down
# Construct string of all possibles except the last
poss_list = ','.join(possibles[:len(possibles)-1])
#Printing First Suggestions
print("You could try {0:s} and {1:s}".format(poss_list,possibles[-1]))