代码1中的一些修改能否取代代码2?
代码1=(这里面的错误是什么?纠正后这个代码能正常工作吗?(
row1 = ["⬜️","⬜️","⬜️"]
row2 = ["⬜️","⬜️","⬜️"]
row3 = ["⬜️","⬜️","⬜️"]
map = [row1, row2, row3]
print(f"{row1}n{row2}n{row3}")
position = (int(input("Where do you want to put the treasure? "))
if position==11:
a=row1[0]="X"
elif position==12:
row1[1]="X"
elif position==13:
row1[2]="X"
elif position==21:
row2[0]="X"
elif position==22:
row2[1]="X"
elif position==23:
row2[2]="X"
elif position==31:
row3[0]="X"
elif position==32:
row3[1]="X"
elif position==33:
row3[2]="X"
代码2=
row1 = ["⬜️","⬜️","⬜️"]
row2 = ["⬜️","⬜️","⬜️"]
row3 = ["⬜️","⬜️","⬜️"]
map = [row1, row2, row3]
print(f"{row1}n{row2}n{row3}")
position = input("Where do you want to put the treasure? ")
horizantal=int(position[0])#2
vertical=int(position[1])#3
map[vertical-1][horizantal-1]="X"
selected_row=map[vertical - 1 ]
selected_row[ horizanta l - 1 ]="X"
print(f"{row1}n{row2}n{row3}")
在代码1中,这一行缺少一个括号:
position = (int(input("Where do you want to put the treasure? "))
修改为:
position = (int(input("Where do you want to put the treasure? ")))