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]=""