Hacks (0.3)

  • Make your own list and manipulate it via accessing specific elements, adding or removing elements, etc.
  • Extra: Make an interactable visualization that can manipulate elements in a list such as the one demonstrated in our flask repository

Append and remove

games = ["Apex", "Fortnite", "Rocket League"]
games.append("PubG")
print(games)
games.remove("PubG")
print(games)
['Apex', 'Fortnite', 'Rocket League', 'PubG']
['Apex', 'Fortnite', 'Rocket League']

Insert and Modify

games = ["Apex", "Fortnite", "Rocket League"]
games.insert(1,"Clash Royale")
print(games)
games[1] = "Brawl Stars"
print(games)
['Apex', 'Clash Royale', 'Fortnite', 'Rocket League']
['Apex', 'Brawl Stars', 'Fortnite', 'Rocket League']

Pop and Clear

games = ["Apex", "Fortnite", "Rocket League"]
games.pop(1)
print(games)
games.clear()
print(games)
['Apex', 'Rocket League']
[]

Popcorn hack (0.3)

  • Make a list related to your CPT project
  • Make a while loop that will print each term in the list
  • Make a for loop that will print each term in the list

Simulation mechanics

  • In Python, pop() is a method that is used to remove and return an element from a list. The syntax for using pop() is as follows:
colors = ["red", "green", "blue", "purple", "orange"]

def whileLoop():
    print("WHILE LOOP:\n")
    # i is the iteration variable
    # num is regarding the index
    i = 0
    num = 0
    # While loop
    while i<5:
        i = i +1
        # printing color of specified index
        print(colors[num])
        # adding to go down index
        num = num +1
whileLoop()

print("")
print("")



def forLoop():
    print("FOR LOOP:\n")
    # for each color in the list, print
    for x in colors:
        print(x)
forLoop()
WHILE LOOP:

red
green
blue
purple
orange


FOR LOOP:

red
green
blue
purple
orange