Quiz - Python Tutorial

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

11/2/23, 8:37 PM Quiz: Python Tutorial: Attempt review

Started on Wednesday, 18 October 2023, 8:16 PM


State Finished
Completed on Wednesday, 18 October 2023, 8:21 PM
Time taken 4 mins 47 secs
Marks 28.00/30.00
Grade 3.73 out of 4.00 (93.33%)

Question 1
Correct

Mark 1.00 out of 1.00

Assume you want to print out "Hello Ilmenau" if var1 is set to True. Please complete the following code accordingly.

if var1 ==  True:

print("Hello Ilmenau")

Your answer is correct.


The correct answer is: Assume you want to print out "Hello Ilmenau" if var1 is set to True. Please complete the following code accordingly.

if var1 [==] True:


print("Hello Ilmenau")

Question 2

Correct

Mark 1.00 out of 1.00

Which value does the variable var have after the following lines of code.

var = "Test text"


var = 1

a. The assignment var = 1 causes an error, as var is a string variable and we try to assign a numerical value to it.

b. The value of var equals to 1, as the initial value is overwritten in the second line. 

c. The value of var equals to "Test text", as the value of the variable can no longer be changed after the first line.

Your answer is correct.

The correct answer is:


The value of var equals to 1, as the initial value is overwritten in the second line.

https://moodle.tu-ilmenau.de/mod/quiz/review.php?attempt=885&cmid=18593 1/11
11/2/23, 8:37 PM Quiz: Python Tutorial: Attempt review

Question 3

Correct

Mark 1.00 out of 1.00

Select all benefits of using functions.

a. Functions help to increase the maintainability of code. 

b. Functions help to speed up the code execution.

c. Functions help to increase the readability of code. 

d. Functions help to debug code. 

e. Functions help to distribute code development. 

Your answer is correct.

The correct answers are:


Functions help to increase the readability of code.,
Functions help to increase the maintainability of code.,

Functions help to distribute code development.,

Functions help to debug code.

Question 4
Correct

Mark 1.00 out of 1.00

Select all correct statements about Python.

a. Python source code that runs on Windows systems cannot run on Linux systems without changes.
b. Python source code is always compiled to highly optimized machine code and only the compiled binary files are distributed.
c. Usually the Python source code is shared and the source code is run using an interpreter. 

Your answer is correct.

The correct answer is:


Usually the Python source code is shared and the source code is run using an interpreter.

https://moodle.tu-ilmenau.de/mod/quiz/review.php?attempt=885&cmid=18593 2/11
11/2/23, 8:37 PM Quiz: Python Tutorial: Attempt review

Question 5

Correct

Mark 1.00 out of 1.00

Assume the following program code.


var1 = {'one':1, 'two':2, 'three':3}
var1['zero'] = 0

Is the following statement true or false?


Executing the code results in an error, as it is not possible to insert new elements at the beginning of an existing dictionary.

Select one:

True

False 

The correct answer is 'False'.

Question 6
Correct

Mark 6.00 out of 6.00

For and While Loops are an efficient way to repeat lines of code. for  loops are especially useful if the number of iterations
is known beforehand or when iterating over an array. while  loops are often used if the number of iterations is initially not
known, e.g., if code should be iterated until a given condition is met.

In most cases, for  loops should be preferred over while  loops, as while  loops bear a
risk of creating infinite loops  .

for

memory leaks calculation errors for while

Your answer is correct.


The correct answer is:
For and While Loops are an efficient way to repeat lines of code. [for] loops are especially useful if the number of iterations is known
beforehand or when iterating over an array. [while] loops are often used if the number of iterations is initially not known, e.g., if code should
be iterated until a given condition is met.

In most cases, [for] loops should be preferred over [while] loops, as [while] loops bear a risk of creating [infinite loops].

https://moodle.tu-ilmenau.de/mod/quiz/review.php?attempt=885&cmid=18593 3/11
11/2/23, 8:37 PM Quiz: Python Tutorial: Attempt review

Question 7

Correct

Mark 1.00 out of 1.00

Assume the list var1 = ['1','2',3,4,5 ] . Which output does print(var1[1]) produce?

a. 2 

b. 1

c. The command produces an error, as the list contains strings and numbers.
d. 3

Your answer is correct.

The correct answer is:


2

Question 8
Correct

Mark 1.00 out of 1.00

Is the following statement true or false?

A Python source code file must have the file ending .py so that the Python interpreter can run the program.

Select one:

True

False 

The correct answer is 'False'.

https://moodle.tu-ilmenau.de/mod/quiz/review.php?attempt=885&cmid=18593 4/11
11/2/23, 8:37 PM Quiz: Python Tutorial: Attempt review

Question 9

Incorrect

Mark 0.00 out of 1.00

Assume you want to define a variable in Python. What do you have to keep in mind?

a. The variable is dynamically typed, but there is no automatic type conversion.

b. The variable is not dynamically typed, but there is automatic type conversion.

c. The variable is dynamically typed, and there is automatic type conversion. 

d. The variable is not dynamically typed, but there is no automatic type conversion.

Your answer is incorrect.


The correct answer is:
The variable is dynamically typed, but there is no automatic type conversion.

Question 10
Correct

Mark 1.00 out of 1.00

Is the following statement true or false?

A Python interpreter and a text editor are sufficient to start programming Python. An integrated development environment is not required.

Select one:

True 

False

The correct answer is 'True'.

https://moodle.tu-ilmenau.de/mod/quiz/review.php?attempt=885&cmid=18593 5/11
11/2/23, 8:37 PM Quiz: Python Tutorial: Attempt review

Question 11

Partially correct

Mark 5.00 out of 6.00

Python 2 was released before  Python 3, and many libraries are using Python 2. Python 2 and Python 3 are
not fully compatible  , i.e., program code following the specifications of Python 3 runs not necessarily  on
Python 2 interpreters. It is recommended to follow the programming specifications of Python 3  , as
Python 2  is not compatible  .

at the same time as never really adapted

always not developed further never

fully compatible

only available as beta‑version after

Your answer is partially correct.

You have correctly selected 5.


The correct answer is:
Python 2 was released [before] Python 3, and many libraries are using Python 2. Python 2 and Python 3 are [not fully compatible], i.e., program
code following the specifications of Python 3 runs [not necessarily] on Python 2 interpreters. It is recommended to follow the programming
specifications of [Python 3], as [Python 2] is [not developed further] .

Question 12
Correct

Mark 1.00 out of 1.00

How can you find out the version of the default Python interpreter on a command line?

a. It is not possible to identify the version of the python interpreter on the command line.

b. python --version 

c. python -show_version

d. python --is_python2?

Your answer is correct.

The correct answer is:


python --version

https://moodle.tu-ilmenau.de/mod/quiz/review.php?attempt=885&cmid=18593 6/11
11/2/23, 8:37 PM Quiz: Python Tutorial: Attempt review

Question 13

Correct

Mark 1.00 out of 1.00

Is the following statement true or false?

Python is a relatively new programming language that was first released in 2008.

Select one:

True

False 

The correct answer is 'False'.

Question 14
Correct

Mark 1.00 out of 1.00

Running the python command on a command line always starts the

a. The default Python interpreter of the system. This might be a Python 2 or Python 3 interpreter. 

b. Python 2 interpreter

c. Python 3 interpreter

Your answer is correct.

The correct answer is:


The default Python interpreter of the system. This might be a Python 2 or Python 3 interpreter.

https://moodle.tu-ilmenau.de/mod/quiz/review.php?attempt=885&cmid=18593 7/11
11/2/23, 8:37 PM Quiz: Python Tutorial: Attempt review

Question 15

Correct

Mark 1.00 out of 1.00

Assume the following program code.

var1 = {'one':1, 'two':2, 'three':3}


var1['one'] = 2

Is the following statement true or false?

After executing the code the content of var1 is as follows:


var1 = {'one':1, 'one':2, 'two':2, 'three':3}

Select one:

True

False 

The correct answer is 'False'.

Question 16

Correct

Mark 1.00 out of 1.00

Which value does the variable var have after the following line of code.

var = 1 + 2 + "3"

a. The value of var equals to 123, as the three numbers are considered as strings and concatenated.

b. The assignment causes an error, as it is not possible to add two number in one line of code.

c. The value of var equals to 33. The first two numbers are added and then the result is concatenated with the string "3".

d. The value of var equals to 6, as the three numbers are added.

e. The assignment causes an error, as it is not possible to add strings and numbers. 

Your answer is correct.

The correct answer is:


The assignment causes an error, as it is not possible to add strings and numbers.

https://moodle.tu-ilmenau.de/mod/quiz/review.php?attempt=885&cmid=18593 8/11
11/2/23, 8:37 PM Quiz: Python Tutorial: Attempt review

Question 17

Correct

Mark 1.00 out of 1.00

Assume the following program code.


var1 = {'one':1, 'two':2, 'three':3}
var1['three'] = 2

Is the following statement true or false?


Executing the code results in an error, as the key "three" already exists.

Select one:

True

False 

The correct answer is 'False'.

Question 18
Correct

Mark 1.00 out of 1.00

Assume the two following code snippets.


snippet 1)
var1=0
if var1==0:
var1=1
print(var1)

snippet 2)
var1=0
if var1==0:
var1=1
print(var1)

Is the following statement true or false?


Snippet 2 produced an error, while snippet 1 does not.

Select one:

True 

False

This answer is correct. The print command in snippet 2 has a wrong indention. All other code as either no leading spaces or 3 leading spaces,
the print command has only one leading space. This results in an error message and the code will not run.

The correct answer is 'True'.

https://moodle.tu-ilmenau.de/mod/quiz/review.php?attempt=885&cmid=18593 9/11
11/2/23, 8:37 PM Quiz: Python Tutorial: Attempt review

Question 19

Correct

Mark 1.00 out of 1.00

Assume you want to execute different statements based on the values of the variables var1 and var2. Which of the following solutions is
preferable.

a.
if var1==0:
if var2==0:
# statements
if var2==1:
# statements
if var2 != 0 and var2 !=1:
# statements

if var1==1
if var2==0:
# statements
if var2==1:
# statements
if var2 != 0 and var2 !=1:
# statements

if var1!=0 and var1!=1:


# statements

b.
if var1==0 and var2==0:
# statements

if var1==1 and var2==0:


# statements

if var1==0 and var2==1:


# statements
if var1==1 and var2==1:
# statements

if (var1!=0 and var1!=1) or (var2!=0 and var2!=1):


# statements

c. if var1==0 and var2==0: 


# statements
elif var1==1 and var2==0:
# statements
elif var1==0 and var2==1:
# statements
elif var1==1 and var2==1:
# statements
else:
# statements

Your answer is correct.

The correct answer is:

https://moodle.tu-ilmenau.de/mod/quiz/review.php?attempt=885&cmid=18593 10/11
11/2/23, 8:37 PM Quiz: Python Tutorial: Attempt review
if var1==0 and var2==0:
# statements
elif var1==1 and var2==0:
# statements
elif var1==0 and var2==1:
# statements
elif var1==1 and var2==1:
# statements
else:
# statements

Question 20
Correct

Mark 1.00 out of 1.00

Is the following statement true or false?


Python is a highly specialized programming language for scientific evaluations and simulations.

Select one:

True

False 

The correct answer is 'False'.

Impressum Datenschutz Betriebsregeln

https://moodle.tu-ilmenau.de/mod/quiz/review.php?attempt=885&cmid=18593 11/11

You might also like