Which of thse variable names would be the best choice?
A. t
B. tl
C. timeLeft
D. TL
C. timeLeft
Using variable names that describe what they do is good programming practice. Later, when you or another programmer comes along to make edits, it will be clear what the variable is intended for.
What is the resulting value of x in the following expression?
x = 16//5
3
Two slashes is integer division, meaning the result is given as an integer, with any decimal simply dropped off.
In the following scenario:
a = 5
print(a)
Wile the "print" will automatically convert "a" to a string or result in an error?
Yes, it automatically converts the int 5 to a string "5".
How do we load a module? For instance, random?
import random
What does the following code output?
for i in range(30, 51, 3):
print(i)
30
33
36
39
42
45
48
Which of the following variable names are considered to be in camel case?
A. my_count
B. myCount
C. mycount
D. turtle
B. myCount
Camel case is described as using variable names where each subsequent word has a capital letter. The first letter may or may not be capitalized. This is generally referred to as either upper camel case or lower camel case. In our example, we are using lower camel case.
What is the result of the following expression?
s = "abc" + "def" * 3
print(s)
abcdefdefdef
If you divide two integers like so:
num = 6 / 2
What is the TYPE of the resulting number?
float
Division in Python, even between two integers, results in a float type.
Whenever a module is loaded using "import" it is always only functions that are imported.
A. true
B. false
FALSE
In the following code snippet:
for i in range(30, 51, 3):
print(i)
Instead of 51, what other values could be provided to give the same output?
49, 50, or 51 will output:
30
33
36
39
42
45
48
Which of the following is an appropriate variable name?
A. 2count
B. count two
C. "count2"
D. count2
D. count2
Variable names cannot start with numbers, or have spaces. Quotes makes something a string literal.
a = 2
b = 3
c = "c"
s = "a" * b + "b" + c
print(s)
aaabc
What is the result of the following expression:
print(str("c" * 4))
cccc
What is the seed method of the random library used for?
To generate the same set of random values again.
After creating a new turtle, to draw a line up by 200 pixels, what command(s) would you use?
t.left(90) # Face upward
t.forward(20) # Draw the line up
Which of the following are keywords in Python? There could be more than one.
A. continue
B. else
C. do
D. for
A, B, and D are keywords, and therefore cannot be used for variable names.
a = "csc231"
b = "231"
print(a in b)
True
The expression "a in b" is a boolean expression, which will equate to the values True or False.
What is the result of the following expression:
print(str(3/4 + 2.0))
The string "2.75"
If you wanted to generate a random number between 1 and 8, inclusively, what command would you use and with what arguments?
random.randrange(1, 9)
Fruitful functions must contain what keyword?
return
Because they must return a value to be "fruitful".
What is the output of the following code snippet?
a = 7.6
b = int(a)
print(b)
7
The variable b becomes an integer representation of a, meaning the decimal is simply dropped off.
What is the output of the following expression?
c = "ab"
a = "c"
print(a in c)
False
"c" is not in the string "ab"
What is the result of the following expression?
a = 10.0
b = 10
print(a == b)
True
You can numerically compare floats and ints and get resulting true values when they are equal.
What is the difference between the randon.rangerange() method and random.randint() method?
They both retrieve a random number between 2 provided numbers, but randint is inclusive and randrange is not, meaning it does not include the second argument given to it. Additionally, randrange takes an optional third parameter "step" that allows you to count by different increments.
Which of the following are true statements?
A. You can have more than one turtle in your program
B. The turtle can only move by leaving a visible line
C. Turtle graphics is a 3D graphics library
D. Only one line width is possible with turtle
E. The turtle color can be changed
A and E are true.
Turtle is only a 2D graphics library, the turtle line width can be changed, and you can move a turtle around without drawing a line using the penup() method.