Jed Rembold & Fred Agbo
February 28, 2024
Which of the below blocks of code will create the image to the right?
The window measures 500 x 200 pixels and the value of
d
is 150.
x, y = 250 - d / 2, 100 - d / 2
a1 = GArc(x, y, d, d, 90, -180)
gw.add(a1)
x, y = 250 - d, 100 - d
a1 = GArc(x, y, d, d, -180, 90)
gw.add(a1)
x, y = 250 - d / 2, 100 - d / 2
a1 = GArc(x, y, d, d, 90, 180)
gw.add(a1)
x, y = 250 - d / 2, 100 - d / 2
a1 = GArc(x, y, d, 180, -90)
gw.add(a1)
Created using square brackets with elements separated by commas:
COIN_VALUES = [1, 5, 10, 25, 50, 100]
COIN_NAMES = [ "penny", "nickle", "dime",
"quarter", "half-dollar", "dollar" ]
Lists are commonly represented visually or conceptually as a series of numbered boxes:
Can retrieve the value of any element in a list by writing the index of that element in square brackets after the list name
COIN_VALUES[3]
⟶
25
COIN_NAMES[2]
⟶
"dime"
Can concatenate two lists to form a new list with elements from both
[1,2,3] + [4,5,6]
⟶
[1,2,3,4,5,6]
Can loop through each of the list elements in turn
for elem in my_list:
# do stuff with elem
where elem
is the name of the variable
that will sequentially get assigned the value of every element in
my_list
len
function+
or
+=
*
in
operatorWhat would the below expression evaluate to?
[“One”, 2, True][-1:1:-1][1]
"n"
2
True
cool = ['blue', 'violet']
warm = ['red', 'orange']
colors = [cool, warm]
other_colors = [['blue', 'violet'],
['red', 'orange']]
print(colors == other_colors)
print(colors is other_colors)
cool[0] = 'indigo'
warm = ['orange', 'yellow']
print(colors)
print(other_colors)