WorksheetsCOSC 1 Final
Total questions: 15
Worksheet time: 45mins
Which of the following best describes how Python statements are executed?
All at once
One line at a time: top to bottom
One line at a time: bottom to top
In batches of 10 lines at a time
Which of these print statements will not give you an error?
print("hello world")
print=("hello world")
print(int("hello world)
print "hello world"
What is the purpose of leaving comments in your source code?
To make code easier for humans to understand
So python gets a break when running the code
To slow down the speed of the code
All of these are true
Which of the following variable names are invalid?
123Gaming
GamingpC
all of them
Gaming_123
Which of the following values is not a valid integer?
5
51000
-100
-12.3
Which of the following is not a valid floating point number?
"Floating Point"
5.554
-12.3
All of these are valid
If you concatenate strings together with the plus sign (+), which of the following statements is true?
No spaces will be added to separate the parts within the output string
A space will be automatically added to separate each part within the output string
The resulting string must be less than 128 characters in length
Only the longer input string will appear in the output string
Which of the following statements will convert a string stored in "inputResults" to an integer variable called "age"?
age.int(inputResults)
age = int(inputResults)
inputResults = parse(age)
age = inputResults.parse()
If "numGrapes" is equal to 10, which of the following expressions will produce a False result?
numGrapes != 10
All of these are False
numGrapes < 9
numGrapes >= 11
If food="milkshake" and flavor="chocolate", what is the result of the following logical expression?
(food == "milkshake" and flavor == "vanilla")
Milkshake
Vanilla
False
True
If you want to print "Password verified" when the user guesses the matching password, what is wrong with the following code?
password = "SECRET"
guess = input("What's the password? ")
if (guess != password):
print("Password verified")
else:
print("Access denied")
It will show a syntax error
It will print the opposite of what you want due to a logical error
Nothing is wrong; it will do exactly what you want
It will throw a runtime exception
Which function do we suggest using to create your program trace statements?
breakpoint()
print()
trace()
display()
What is displayed on the screen when the following code runs?
esports = ["Donkey Kong", "Galaga", "Pac Man"]
if ("Galaga" in esports):
print("Found it")
else:
print("Not here")
Nothing is printed out
Found it
Not here
Both "Found it" and "Not here"
What value is stored in the "total" variable after the following code runs?
total = 0
for i in range(1,4):
total = total + i
6
0
5
10
Which of the following best describes how many times the statements in the body of a "while" loop will run?
0, 1 or more times depending on the logical expression of the "while" statement
At least once
A maximum of 10 times no matter what
An infinite number of times until a "continue" statement is reached
