Hacks: Your Score/1

General 0.3

  • Copy this noteboook into your personal fastpages
  • Answer all questions
    • put the question in a new markdown block (so we can grade faster)

All Questions

1: 2D Array

Tic Tac Toe:Kush Sirohi

  • What are some examples of 2d Arrays
    • Tic-tac-toe game board: This is a classic example of a 2D array, where the game board is represented as a 3x3 grid.
- Spreadsheet software: Spreadsheets are often organized as a 2D arrays for a modern-day game that could be classified as a 2D array, a good example would be the popular puzzle game "Sudoku". In Sudoku, the game board is represented as a 9x9 grid of cells, with each cell containing a number from 1 to 9. The game involves filling in the missing numbers in each row, column, and 3x3 sub-grid, following certain rules. The game board can be easily represented as a 2D array in programming, with each cell being an element in the array.y of cells, where each cell has a row and column index.

- Pixel art: Pixel art is often created on a 2D grid, where each square represents a pixel in the image.
  • What is a modern day game that could be classified as a 2D array
    • As for a modern-day game that could be classified as a 2D array, a good example would be the popular puzzle game "Sudoku". In Sudoku, the game board is represented as a 9x9 grid of cells, with each cell containing a number from 1 to 9. The game involves filling in the missing numbers in each row, column, and 3x3 sub-grid, following certain rules. The game board can be easily represented as a 2D array in programming, with each cell being an element in the array. ## How I used 2D Arrays (game example)
  • Describe a 2D array in your own words
    • A 2D array is a grid that stores data in rows and columns, commonly used in programming to represent data in a two-dimensional space. ## 2: Iteration

      Robot Game:Finn Carpenter- What is the defenition of iteration in your own words

    • Iterations mean repeating a set of instructions or steps multiple times, often used in programming to execute a block of code repeatedly to achieve a specific goal. ## How I used iteration (game example)
  • What parts of the code use iteration
    • the movements ## How I used List to make a game
  • Explain which parts of the code use lists
    • it uses a list to store the words
  • Explain what list manipulation is happening in that part
    • a word is being randomly selected from the list and being scrambled

Iteration 0.2 (can get up to 0.23)

  • Get to level 5
    • Take ScreenShots of your name inside the box an put them in your ticket
  • Create a code segment with iteration that does something cool
limit = int(input("Enter a limit for the Fibonacci sequence: "))

# initialize the first two numbers in the sequence
a, b = 0, 1

# iterate through the sequence and print each number
while a < limit:
    print(a)
    a, b = b, a + b

2D array 0.2 (can get up to 0.23)

  • Explain how the tic tac toe game works
    • The game is played on a 3x3 board represented by a nested list called 'board'. The 'print_board()' function prints the current state of the board, showing the row and column indices and the symbols ('X' or 'O') that have been placed on the board. The 'check_win(player)' function checks if the player who made the move has won the game. It checks for winning combinations on the rows, columns, and diagonals of the board. The 'check_tie()' function checks if the game is a tie. If all the spaces on the board have been filled and no player has won, the game is a tie. The 'play_game()' function starts the game loop. It initializes the player to 'X' and the turn counter to 0. In each iteration of the loop, it prints the current state of the board, prompts the player for their move, checks if the move is valid, updates the board, checks if the player has won or the game is a tie, switches to the other player if the game is not over, and repeats the loop. Finally, the 'play_game()' function is called to start the game. It prints the initial state of the board and starts the game loop until a winner is found or the game ends in a tie.
  • Give 3 Examples of games that can be made from 2D arrays

    • Tic-Tac-Toe: A 2D array can represent a 3x3 grid for the game, with each element storing a value ('X', 'O', or empty) for the current state of the game.

    • Minesweeper: A 2D array can represent a grid for the game, with each element storing a value (mine or not, covered or uncovered) for the state of each cell.

    • Sokoban: A 2D array can represent a grid for the game, with each element representing a tile. The player and boxes can be separate objects that move around the grid, with the state of the game updated by checking for collisions and events.

List and Dictionaries 0.2 (can get up to 0.23)

  • Explain the differences between Lists and Dictionaries
    • Lists are ordered collections of items, where each item is assigned an index based on its position in the list. Lists are created using square brackets, and items are separated by commas. Lists can contain any type of data, including other lists.
  • Make a code block that manipulates either a list or a dictionary
my_dict = {'apple': 3, 'banana': 1, 'orange': 2}

# Convert the dictionary into a list of tuples
my_list = list(my_dict.items())

# Sort the list by the values in descending order
my_list.sort(key=lambda x: x[1], reverse=True)

# Convert the list back to a dictionary
sorted_dict = dict(my_list)

print(sorted_dict)
{'apple': 3, 'orange': 2, 'banana': 1}