console.write("Insert new third animal:")zooanimals(2)=console.readline()console.writeline("1: "&zooanimals(0))console.writeline("2: "&zooanimals(1))console.writeline("3: "&zooanimals(2))console.writeline("4: "&zooanimals(3))console.writeline("5: "&zooanimals(4))''Alternatively an A-grade student might write:forx=0to4console.writeline(x+1&": "&zooanimals(x))next
zooanimals[2]=input("Insert new third animal: ")print("1:",zooanimals[0])print("2:",zooanimals[1])print("3:",zooanimals[2])print("4:",zooanimals[3])print("5:",zooanimals[4])#Alternatively an A-grade student might write:forxinrange(5):print(x,": ",zooanimals[x],sep="")
Dimx,yAsIntegerDimboard(3,3)AsCharboard(0,0)="x"board(0,1)="o"board(0,2)="o"board(1,0)="o"board(1,1)="o"board(1,2)="x"board(2,0)="o"board(2,1)="o"board(2,2)="o"board(2,0)="o"board(2,1)="o"board(2,2)="o"Forz=1To3Console.WriteLine("This is guess number "&z)Console.Write("please insert your x location:")x=Console.ReadLine()Console.Write("please insert your y location:")y=Console.ReadLine()Ifboard(x,y)="x"ThenConsole.WriteLine("you win!")EndIfNext
board=[[""forxinrange(3)]forxinrange(3)]board[0][0]="x"board[0][1]="o"board[0][2]="o"board[1][0]="o"board[1][1]="o"board[1][2]="x"board[2][0]="o"board[2][1]="o"board[2][2]="o"board[2][0]="o"board[2][1]="o"board[2][2]="o"forzinrange(1,4):print("This is guess number",z)x=int(input("please insert your x location: "))y=int(input("please insert your y location: "))ifboard[x][y]=="x":print("you win!")
声明一个 chessBoard(8*8 个方格),用 b 表示黑色,w 表示白色,以编程方式对其进行着色。您可能想在上面的棋盘格颜色分配中寻找一个模式,并与MOD 函数交朋友。
您也可能想在尝试回答这个问题时变得有点循环
答案
VB.NET
Python
dimchessBoard(8,8)aschar'also chessBoard(7,7)forx=1to8fory=1to8if(x+y)MOD2=1thenchessBoard(x,y)="w"elsechessBoard(x,y)="b"endifnextnextdisplay(chessBoard())' using a slightly updated version of the subroutine display()
chessBoard=[[""forxinrange(8)]forxinrange(8)]forxinrange(8):foryinrange(8):if(x+y)%2==1:chessBoard[x][y]="w"else:chessBoard[x][y]="b"display(chessBoard)# using a slightly updated version of the subroutine display()
如果您完成了这项工作,您可能想让程序打印一些巨大的棋盘,无论什么能使您兴奋。
使用以下二维数组,grid(4,4)
编写代码以输出名称 CRAIG
在第 2 行(第三行)插入 MARY
用 SAM 覆盖 STEVE
答案
VB.NET
Python
Console.Writeline(grid(3,0)&grid(3,1)&grid(3,2)&grid(3,3)&grid(3,4))grid(2,0)="M"grid(2,1)="A"grid(2,2)="R"grid(2,3)="Y"grid(1,0)="S"' you could skip thisgrid(1,1)="A"grid(1,2)="M"grid(1,3)=""grid(1,4)=""
print(grid[3][0]+grid[3][1]+grid[3][2]+grid[3][3]+grid[3][4])grid[2][0]="M"grid[2][1]="A"grid[2][2]="R"grid[2][3]="Y"grid[1][0]="S"# you could skip thisgrid[1][1]="A"grid[1][2]="M"grid[1][3]=""grid[1][4]=""