This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
I am writing a class called GenericCar and trying to create a new car object | |
that should be blue. I got stuck when trying to pass in the car color, but | |
I'm not sure how to solve the issue. I tried looking at the p5.js reference | |
section for help, but I'm not sure how to use it yet. | |
*/ | |
function setup(){ | |
createCanvas(400, 400); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setup(){ | |
createCanvas(400, 400); | |
} | |
function draw(){ | |
var fastCar = new GenericCar(100, 55, "blueu"); | |
fastCar.drawCar() | |
} | |
class GenericCar { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def length(self): | |
"""Return the length of this linked list by traversing its nodes.""" | |
node_count = 0 # initial count is zero | |
current = self.head # start at the head | |
# Loop through all nodes | |
while current is not None: | |
current = current.next | |
# add one to the counter each time | |
node_count += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for name in name_list: # we go over every name in the list | |
name = name.title() # we change every name | |
counter += 1 # each time, we add 1 more to the counter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all_students_stuff = { | |
"bob": { | |
"clothing": ["sneakers", "hat"], | |
"storage": ["backpack"], | |
"food": ["apple sauce", "sandwich"] | |
}, | |
"marie": { | |
"clothing": ["gloves", "cleats"], | |
"hair stuff": ["hair brush"] | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all_students_stuff = { | |
"bob": ["backpack", "sneakers", "hat"], | |
"elena": ["gloves", "hair brush", "cleats"], | |
"piper": ["backpack", "sneakers", "hat"] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list2.insert(0, 1) # inserting number 1 at index 0 | |
list2.pop() # removing the last value | |
list1 = [1, 2, 3] | |
list2 = [1, 2, 3] | |
# oh no! which value will we get? | |
dictionary = { | |
# list1 = [1, 2, 3] | |
list1: "a_value", | |
# list 2 = [1, 2, 3] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list2.insert(0, 1) # inserting number 1 at index 0 | |
list2.pop() # removing the last value | |
list1 = [1, 2, 3] | |
list2 = [1, 2, 3] | |
# oh no! which value will we get? | |
dictionary = { | |
# list1 = [1, 2, 3] | |
list1: "a_value", | |
# list 2 = [1, 2, 3] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list1 = [1, 2, 3] | |
list2 = [2, 3, 4] # different | |
# luckily the keys are unique here | |
dictionary = { | |
# list1 = [1, 2, 3] | |
list1: "a_value", | |
# list 2 = [2, 3, 4] | |
list2: "another_value" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this dictionary only has one entry | |
example_dictionary = {"key": "value"} | |
# this dictionary has multiple entries | |
another_dictionary = { | |
"first_key": "cool_value", | |
"second_key": "awesome_value", | |
"lots_of_keys": "cool_value" | |
} |
NewerOlder