Final 6 Flashcards
Does python’s “a variable is a pointer to a value” idea make it easier for variables to change size?
Yes
According to lectures, when we change the value
of a variable, does the interpreter accomplish this by changing the value at the place pointed to by the variable, or does the interpreter accomplish this by moving the pointer over to point to another place in memory that has the new desired value.
a) first way b) second way
b) second way
Can we change a variable’s type at runtime?
Yes
According to lectures, are constants and variables declared the same way in Python?
Yes
Would you expect = or == to be used in the expression of an if statement?
==
How many ways are there to declare a variable in Python as expressed in class lectures?
One
Is it normal to execute pseudo code?
No, pseudo code is not executable
What happens when a variable (all of it, not a part of it) is assigned a value?
New value is put into some place of memory, and then the pointer value of the variable is changed to now point to this new place.
What is one advantage of Pythons indention policy over C’s use of brackets
to show what code belongs within an if, etc.
Prevents disconnect between what the human reading the code understands it to mean and what the interpreter understands it to mean because it means the same thing to both. Less ambiguous.
what it the output of
print(“aaaaa”,end=””);print(“bbb”,end=””);print(“c”);print(“d”)
aaaaabbbc
d
what is the output of
print(1,2,3,sep=””)
123
(default sep is a space, sep=”” removes it)
When doing expressions like (5 + 5.0)
the Python interpreter first turns the integer
5 into a float
a) True B) False
a) True, the integer 5 will be temporarily converted to a float and the output of the calculation will also be a float.
Given the code
AA = []
write code with the append function
to make AA become the list with 2 elements, both equal to 2
AA = []
AA.append(2)
AA.append(2)
print(AA)
[2, 2]
According to lectures, is it possible for roundoff
errors to cause problems with equality with real numbers
Yes
Starting with aaa = [], add elements 1-500 using a while loop and the append function. This is to say that index 0 of aaa should be 1, index 1 index should be 2, etc., up to the 499 index which should be 500 .
Then, after this first while loop, write a second while loop that prints what is in aaa, one element per line, so that you get the following output:
aaa 1
aaa 2
aaa 3
.
.
.
aaa 500
aaa = []
i = 0
while i < 500:
i += 1
aaa.append(i)
i = 0
while i < 500:
print(“aaa “ + str(aaa[i]))
i += 1