0% found this document useful (0 votes)
6 views6 pages

Python Code Evaluation Questions

The document details a series of programming questions and answers related to Python, covering topics such as string multiplication, variable declarations, loops, function definitions, sets, tuples, and class inheritance. Each question includes feedback on correct and incorrect answers, explaining the reasoning behind the expected outputs. The overall performance indicates a mix of correct and incorrect responses, with a final evaluation score of 87.50 out of 100.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

Python Code Evaluation Questions

The document details a series of programming questions and answers related to Python, covering topics such as string multiplication, variable declarations, loops, function definitions, sets, tuples, and class inheritance. Each question includes feedback on correct and incorrect answers, explaining the reasoning behind the expected outputs. The overall performance indicates a mix of correct and incorrect responses, with a final evaluation score of 87.50 out of 100.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Started on sexta, 12 ago 2022, 15:28

State Completed
Completed on sexta, 12 ago 2022, 18:22
Time spent 2 hours 54 minutes
Notas 7.00/8.00
Evaluate87.50 out of a maximum of 100.00
Question 1
Correct
Reached 1.00 out of 1.00

Mark question

Question text

Given the following code:

print("hello world " * 3)

What is the expected output?

Choose an option:

hello world
hello worldhello worldhello world

hello world * 3

d. "helloworld hello world helloworld"

e. None of the above


Feedback

Your answer is correct.

A is incorrect because it ignores the effect of '* 3'. B and C are incorrect because '* 3' is not
a string, therefore it WILL not be concatenated with the string. D is correct because "* 3" is
understood by the Python compiler as a mathematical operation to print the message
3 times.
Question2
Correct
Reached 1.00 out of 1.00

Mark question
Text of the question

Given the following variable declaration:

if = 10

print(if)

What is the expected output?

Choose an option:

a. 10

b. if
c. Error, because 'if' is not defined

d. Error, because 'if' is a keyword

e. None of the above


Feedback

Your answer is correct.

Given the following variable declaration: D is correct because 'if' is a keyword.


for the if/else condition, the compiler interprets 'if' as the beginning of an if condition, instead of
of a variable name. The value of 10 was never assigned to the variable. A is incorrect because
"if" was not interpreted as a variable. B is incorrect because the string must be included.
for quotes in order to be printed. C is incorrect because the compiler will not handle a
keyword as a variable. The compiler sees "if" and thinks it is the beginning of a condition.
Question 3
Correct
Achieved 1.00 out of 1.00

Mark question

Text of the question

Given the following code:

for i in range(1, 5, 2):

print(i)

What is the expected output?

Choose an option:

a. 1, 3

b. 1, 3, 5

c. 1, 5, 2

d. 1, 2
e. None of the above
Feedback

Your answer is correct.

In a 'for loop' that iterates over a range, the first parameter denotes the starting index,
inclusive, the second parameter represents the stop index, exclusive, and the third parameter
it is the incremental value. In the statement of the interval of the question, it could be read as 'start i '
in 1, stop at 5 but not including 5, increase i by 2". A is the only possible solution that
attend.
Question4
Incorrect
Reached 0.00 out of 1.00

Mark question

Text of the question

Given the following function declaration:

findMax():

return max(5, 7)

What is wrong with the function?

Choose an option:

a. None of the above

b. The keyword 'def' is missing at the beginning to initialize a new function

c. max() is not defined

d. All of the above

e. findMax() has no parameters


Feedback

Your answer is incorrect.

A is incorrect because max() is a built-in function in Python that returns the maximum of
elements. B is incorrect because it is not necessary for all function declarations
have parameters passed to the function, only when necessary. D is the only option
correct because to define a new function in Python, the 'def', which means 'define', must
to be in front of the function name.
Question 5
Correct
Achieved 1.00 out of 1.00
Mark question

Text of the question

Given a list that is converted into a set:

list_ages = [2, 5, 10, 9, 5, 10, 22,1]

set_ages = set(list_ages)

print(set_ages)

What is the expected output?

Choose an option:

a. {2, 5, 10, 9, 22, 1}

b. {2, 5, 10, 9, 5, 10, 22, 1}

c. {1, 2, 5, 9, 10, 22}

d. {1, 2, 5, 5, 9, 10, 10, 22}

e. None of the above.


Feedback

Your answer is correct.

When a list is converted into a set, all duplicates are removed.


(key characteristic of a set) and the elements are ordered in ascending order.
Therefore, C is the only correct answer.
Question 6
Correct
Reached 1.00 out of 1.00

Mark question

Text of the question

Given the following code that declares a new tuple named new_tuple:

new_tuple= (‘x’, ‘y’,’z’)


new_tuple.add('w')

What is the expected output of new_tuple?


Choose an option:

["x","y","z","w"]

(‘w’,‘x’,’y’,’z’)
c. ERROR, because the tuple is immutable.

d. ERROR, because the tuple uses append(), not add()

e. None of the above.


Feedback

Your answer is correct.

The letter C is correct because a tuple is immutable, which means its content cannot be modified.
manipulated. A, B, and C cannot be true because a tuple cannot be changed.
therefore no new element can be added.
Question 7
Correct
Reached 1.00 out of 1.00

Mark question

Text of the question

Given the following code:

class ClownFish():

pass

fish = ClownFish()

isinstance(fish, ClownFish)

What is the expected output?

Choose an option:

a. True

b. False
Feedback

Your answer is correct.

The variable name "fish" is created as an instance of the ClownFish class, so the
The isinstance() check against the ClownFish class should return true.
Question 8
Correto
Reached 1.00 out of 1.00
Mark question

Text of the question

Given the following code:

class Fish():

pass

class ClownFish(Fish):

pass

fish = ClownFish()

isinstance(fish, Fish)

What is the expected output?

Choose an option:

a. True

b. False
Feedback

Your answer is correct.

ClownFish is a child class of Fish(). Since 'fish' is created as an instance


the ClownFish, based on the property of inheritance, is also an instance of the
class Fish. All clownfish are also fish. Instances of the child class have
access to the properties and methods of all parent classes (or grandparents, great-grandparents, etc.) and the option

to overlap with them.

You might also like