COMP II

A vibrant and engaging illustration depicting a computer screen with Python code, books about programming, and a person thoughtfully taking a quiz in a colorful, modern classroom setting.

Master Python with Our Comprehensive Quiz!

Test your Python programming skills with our engaging 40-question quiz designed for students and learners alike. From basic concepts to complex functions, this quiz covers a wide array of topics that will challenge your knowledge and understanding of Python.

Key Features:

  • 40 Multiple Choice Questions
  • Instant Feedback on Answers
  • Improve Your Coding Skills
40 Questions10 MinutesCreated by CodingNinja123
What will be the output of the following code?
count = 5
while count > 0:
circle(50)
forward(100)
5 circles in a row
4 circles in a row
A slinky with 5 circles
An infinite loop will occur
What will be the radii of the circles drawn from the following code?
 
for I in range(10, 55, 10):
circle(i)
10, 20, 30, 40, 50
10, 15, 20, 25, 30, 35, 40, 45, 50, 55
10, 55, 10
10, 20, 30, 40, 50, 55
What is the difference between defining and calling a function?
Defining a function means you are teaching the computer a new word. Calling a function means you are commanding the computer to complete defined actions.
There is no difference.
Calling a function means you are teaching the computer a new word. Defining a function means you are commanding the computer to complete defined actions.
Defining a function must be done each time you want to use the function. Calling a function can only happen once in your code.
Which of the following is NOT a purpose of using functions?
Functions let Tracy do new things.
Functions help group statements together to make your code more readable.
Functions let you execute code a fixed number of times.
Functions allow the programmer to reuse code.
Suppose you write a function. How many times can you call the function in your code?
Once
Not more than the number of commands the function holds
It depends on the function
As many times as you want
What is the difference between a binary operator and a unary operator?
A computer can use binary operators, but it cannot use unary operators.
A unary operator needs two things, while a binary operator only needs one.
A binary operator needs two things, while a unary operator only needs one.
Binary operators are used for arithmetic expressions, while unary operators are for strings.
What is the output of the following program? Assume the user enters “Florence”, then “Fernandez”.
first_name = input("What is your first name? ")
last_name = input("What is your last name? ")
whole_name = first_name + last_name
print whole_name
Fernandez Florence
Florence
Fernandez
FlorenceFernandez
Florence Fernandez
Which of the following statements is true about print statements?
 
I. In order to print a string literal, the string must be enclosed in quotes.
 
II. Each print statement will be printed on its own line.
 
III. Print statements will not let you print strings and numbers in the same statement.
 
IV. Print statements are how you display text on the screen.
I, IV
II, III
I, II, IV
I, III, IV
Which of the following choices is a properly formed Python variable name, meaning it is both legal in the Python language and considered good style?
User_age
uSeRaGe
User!age!
1user_age
Which of the following choices is NOT a Python variable type?
int
Str
Float
number
Choose the correct declaration of a float variable with the value 3.14.
Pi = “3.14”
Pi = int(3.14)
Pi = 3.14
float pi = 3.14
What is the final result of the expression 4 + 5 * 3?
27
12
21
19
Choose the print statement below that will cause an error. Assume that num has the value 6, and name has the value Isabella.
print name + ":"
print num
Print name + " wants " + "num " + "candies"
Print name + ": " + str(num)
Print name + ": " + num
Which one of the statements below will cause an error?
Ans = “hi” * 8
Ans = “hi” + 9
Ans = “hi” + “hi” + “hi”
ans = (“a” * 4) + “b”
What will print to the screen when the following program is run?
number = 5
greater_than_zero = number > 0
print(type(number))
5
True
What will be the output of this program?
 
number = 5
less_than_zero = number < 0

if less_than_zero:
    print(number)

number = number - 10
less_than_zero = number < 0

if less_than_zero:
    print(number)
5
5
-5
5
-5
Nothing will print
What will be the output of this program?
 
number = 5
greater_than_zero = number > 0
less_than_zero = number < 0

if greater_than_zero:
    print(number)
if less_than_zero:
    print(number + 1)
if greater_than_zero and less_than_zero:
    print(number + 2)
if greater_than_zero or less_than_zero:
    print(number + 3)
5
5
7
5
7
8
5
8
What does this program print?
 
favorite_color = "blue"

if favorite_color != "green":
    print "But green is the color of grass!"
if favorite_color == "red":
    print "I like red, too!"
if favorite_color == "blue":
    print "Blue is the best"
if favorite_color != "yellow":
    print "But yellow is the color of school buses!"

But green is the color of grass!
Blue is the best
But yellow is the color of school buses!

But green is the color of grass!
But green is the color of grass!
I like red, too!
Blue is the best
But yellow is the color of school buses!
Blue is the best
Which of the following for loops would print the following numbers?
 
0
1
2
3
4
5
for I in range(5):
    print i
for I in range(1, 5, 1):
    print i
for I in range(6):
    print i
for I in range(0, 5, 1):
    print i
Which of the following programs will NOT cause an error?
say_hi(‘Margaret’)

def say_hi(name):
    print hi  + name
function say_hi(name):
    print hi  + name
def say_hi(first_name=’John’, last_name=’Doe’):
    print hi  + first_name +   + last_name

say_hi(‘Polly Pocket’)
def say_hi(first_name=’John’, last_name):
print hi + first_name + + last_name
 
say_hi(‘Polly’, Pocket’)
Which of the programs below will print the following output?
I would like a green balloon.
def balloon_choice(color): print I would like a + color + balloon.’ balloon_choice(‘green’)
def balloon_choice(color):
    print I would like a  + color +  balloon.’
def balloon_choice():
    print I would like a  + color +  balloon.’

balloon_choice(‘green’)
def balloon_choice():
    print I would like a green balloon.’

balloon_choice(‘green’)

What will be the output of the following program?

a = 4

def print_something():
    a = "code"
    print a * 3

print_something()
12
Code
4
Codecodecode

Consider the following functions.

def fn_a(num):
    if num > 3:
        print "Fizz"

def fn_b(num):
    if num > 2 and num < 4:
        print "Fizz"

Which for loop would print

Fizz
Fizz
for I in range(6):
    fn_b(i+1)
for I in range(6):
    fn_a(i)
    fn_b(i)
for I in range(6):
    fn_a(i)
for I in range(6):
    fn_b(i)

What will be printed when the program below is run?

def add_two(x):
    return x + 2

def multiply_by_three(x):
    return x * 3

def my_function(x):
    return add_two(x) + multiply_by_three(x)

print my_function(12)
 
12
24
50
66

What is the value of num when this loop completes?

num = 0

for I in range(2, 8, 2):
    num = num + i
2
8
12
20

Which of the following for loops will give the same values for I as the loop below?

for I in range(10):
for I in range(11, 0):
For I in range(10, 0, -1):
for I in range(0, 10):
For I in range(0, 11, 1):
Which of the following while loops will cause an infinite loop?
secret_num = 10

while secret_num == 10:
    secret_num = secret_num - 1
secret_num = 10

while secret_num == 10:
    print secret_num
secret_num = 10

while secret_num > 0:
    secret_num = secret_num - 1
secret_num = 10

while secret_num != 10:
    print secret_num
When would a while loop be a better control structure to use than a for loop?
When you need to repeat multiple commands
When you need to repeat something 5 times
When you don’t know how many times something will need to repeat
When the user is inputting how many times to repeat something

What will be printed to the screen when this program is run?

num = 100

while num > 0:
    for I in range(100, 0, -25):
        num = num - I
print num
100
0
-75
-125
-150
-150
-175
175

What function should be used in the blank to capitalize the first letter of the word stored in word?

first_char = word[0]
word = first_char.______() + word[1:]
Upper
Lower
Swapcase
Find

Which of the following choices will print AeCl? Assume the following variables have been defined.

first_name = "Alice"
last_name = "Carmichael"
Print first_name[0] + last_name[0]
Print first_name[0] + last_name[0] + first_name[-1] + last_name[-1]
Print first_name[0] + first_name[-1] + last_name[0] + last_name[-1]
Print first_name[1:] + last_name[1:]
Which of the following expressions will result in “brown”?
 
Let sentence = "The brown lazy dog"
print sentence[4:8]
Print sentence[4:9]
print sentence[3:8]
Print sentence[3:9]

Which of the following expressions will print “L”?

Let word = "PINEAPPLE"

Print word[-4:]
print word[-1]
print word[-2]
Which of the following string operation is illegal? Assume that word = "music".
Word[0] = “M”
Word = word[2] + word[-1]
Word = “musical”
word = word + “al”

What is the output of the following program?

sentence = "the dog"

for letter in sentence:
    print letter + letter
t
h
e

d
o
g
t
h
e

d
o
g
t
h
e

d
o
g
tt
hh
ee

dd
oo
gg
The program will cause an error
Which of the functions below will return a string that is in alternating caps? For example, alt_case("sheep") should return “sHeEp”.
def alt_case(word):
    res = ""
    for I in range(len(word)):
        if I % 2 == 1:
            res + word[i].upper()
        else:
            res + word[i].lower()            
    return res
def alt_case(word):
    res = ""
    return word.swapcase()
def alt_case(word):
    res = ""
    for I in range(word):
        if I % 2 == 1:
            res = res + word[i].upper()
        else:
            res = res + word[i].lower()            
    return res
def alt_case(word):
    res = ""
    for I in range(len(word)):
        if I % 2 == 1:
            res = res + word[i].upper()
        else:
            res = res + word[i].lower()            
    return res
What does “immutable” mean with respect to Python strings?

The variable can be assigned a new value, and the string’s value can be modified.

The variable can be assigned a new value, but the string’s value cannot be modified.
A string variable can never be changed. The variable cannot be assigned a new value, and the string’s value cannot be modified.
The variable cannot be assigned a new value, but the string’s value can be modified.

What is printed out by this program?

word = "killer whale"
print word[0:100]
Killer whal
€killer whale “
Killer whale
The program will throw an error

What does the following program print?

x = "ab"
y = "banana"
print x in y
True
False
0
“ba”

If I’m getting input from a user and having their answer dictate my if/else statement, like so:

happy = input("Are you happy? (yes/no): ")
if happy == "yes":
    draw_smile()
elif happy == "no":
    draw_frown()
else:
    print "Invalid response"

Which string method can I use to make sure that the phrase ‘invalid response’ only displays if the user has typed something other than ‘yes’ or ‘no’, without paying attention to their capitalization?

Upper
Lower
Swapcase
Strip
{"name":"COMP II", "url":"https://www.quiz-maker.com/QPREVIEW","txt":"Test your Python programming skills with our engaging 40-question quiz designed for students and learners alike. From basic concepts to complex functions, this quiz covers a wide array of topics that will challenge your knowledge and understanding of Python.Key Features:40 Multiple Choice QuestionsInstant Feedback on AnswersImprove Your Coding Skills","img":"https:/images/course8.png"}
Powered by: Quiz Maker