Introduction: Zeen

Hello, my name is zeen and today we will be presenting big idea 3. Our topics include 2d arrays, iteration, and lists and dictionaries.

Objectives

Master the concepts of iteration, list, 2d-arrays, Dictionaries, and APIs

Vocab

Here is some vocab during the lesson, you should be familar with them already no need for me to read these out, now I will pass the speaking off to Kush

  • Iteration: A process that repates itself
  • Array: Sometimes called a list, can keep strings and intergers inside it
  • 2D-Array: A collection of data elements arranged in a grid-like structure with rows and columns
  • Mutable: the ability to be changed or modified
  • Key: A Singular identifier that is associated with a certin value

1: 2D Array

Tic Tac Toe:Kush Sirohi

  • What are some examples of 2d Arrays
  • Some examples of 2d Arrays are a setting plan for a room plan layout
  • What is a modern day game that could be classified as a 2D array
  • A modern day game that could be classified as a 2d array could be tic tac toe.

How I used 2D Arrays (game example)

  • Describe a 2D array in your own words
  • A 2d array is basically a data set that is organized into rows and columns.

2: Iteration

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

  • The definition of iteration is basically the repeating process of a certain piece of code because it reduces complexity.

Iteration Game

  • Link to the game
  • Play the levels (only play the first 2 in class)
  • Explain how the game relates to itertation
  • because you are using loops

How I used iteration (game example)

  • What parts of the code use iteration
  • the parts of the code that uses iteration is using if functions.

How I used List to make a game

  • Explain which parts of the code use lists
  • in the beginning, there is a list that holds the information
  • Explain what list manipulation is happening in that part
  • the code is manipulating the list because it is pulling from the list to the guesses.
import random

word_list = ["python", "computer", "programming", "algorithm", "database", "function", "variable", "loop", "iteration", "array", "mutable", "insertion", "deletion", "key", "API"]

word = random.choice(word_list)

scrambled_word = "".join(random.sample(word, len(word)))

print(f"Unscramble the following Computer Science Word: {scrambled_word}")

hints = 1
guesses = 1
guess = ""

while guess != word and guesses <= 4:
    guess = input("What's the unscrambled word? ").lower()
    if guess != word:
        print("Sorry, that's not the word. Try again!")
        if guesses == 1:
            guesses += 1
        elif guesses == 2:
            print(f"Hint 1: The first letter of the word is '{word[0]}'")
            guesses += 1
        elif guesses == 3:
            print(f"Hint 2: The second letter of the word is '{word[1]}'")
            guesses += 1
        else:
            print(f"All 4 Guesses have been used, you didn't unscramble the word, the word was {word}")
            guesses += 1
    else:
        print("Congratulations, you unscrambled the word!")
Unscramble the following Computer Science Word: tenldieo
Congratulations, you unscrambled the word!

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)

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

link

rows = 5

for i in range(rows):
    # print spaces before asterisks to create pyramid shape
    for j in range(rows-i-1):
        print(" ", end="")
    # print asterisks in increasing order
    for j in range(i+1):
        print("* ", end="")
    # move to next line after printing each row
    print()
    * 
   * * 
  * * * 
 * * * * 
* * * * * 

2D array 0.2 (can get up to 0.23)

  • Explain how the tic tac toe game works Tic Tac Toe game works by defining the variable "board" with 3 different lists (which is a 2D array.) It then defines a funtion where it prints the board and a function that checks if there is a win or a tie. Finally, it defines the function "play_game" that has a while loop that contains conditionals. It takes the user's inut and calls the functions defined earlier.
  • Give 3 Examples of games that can be made from 2D arrays

Minesweeper: Minesweeper is a popular single-player game that involves uncovering cells on a grid to find hidden mines. The game is played on a 2D array, where each cell can either be empty or contain a mine. The player's objective is to reveal all the cells that do not contain mines without detonating any mines. The player can deduce the location of mines by using the numbers on the revealed cells, which indicate the number of adjacent cells that contain mines.

Battleship: Battleship is a two-player game that involves guessing the location of the opponent's hidden ships on a 2D grid. Each player has a grid where they place their ships, and the opposing player tries to guess the location of the ships by selecting cells on their own grid. The game is played on a 2D array, where each cell can either be empty or contain a ship. The objective of the game is to sink all the opponent's ships.

Snake: Snake is a classic arcade game where the player controls a snake that moves around a 2D grid, eating food and growing in length. The game is played on a 2D array, where each cell can either be empty or contain food. The snake moves continuously in a particular direction, and the player must steer the snake to avoid running into walls or its own tail. The objective of the game is to eat as much food as possible without crashing the snake.

List and Dictionaries 0.2 (can get up to 0.23)

  • The difference between lists and dictionaries: lists use [] dictionaries use {} lists have items dictionaries have keys and values lists are ordered dictionaries are unordered Lists can contain elements of any data type (dictionaries can't with keys) Lists can be accessed with index numbers Dictionaries can be accessed with keys

  • Make a code block that manipulates either a list or a dictionary

numbers = [5, 1, 4, 2, 8]
sorted_numbers = sorted(numbers)
print(sorted_numbers)
[1, 2, 4, 5, 8]