Quiz - Python Tutorial
Quiz - Python Tutorial
Question 1
Correct
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
Which value does the variable var have after the following lines of code.
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.
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
Question 4
Correct
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.
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
Select one:
True
False
Question 6
Correct
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
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
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
Question 8
Correct
A Python source code file must have the file ending .py so that the Python interpreter can run the program.
Select one:
True
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
Assume you want to define a variable in Python. What do you have to keep in mind?
b. The variable is not dynamically typed, but there is automatic type conversion.
d. The variable is not dynamically typed, but there is no automatic type conversion.
Question 10
Correct
A Python interpreter and a text editor are sufficient to start programming Python. An integrated development environment is not required.
Select one:
True
False
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
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 .
fully compatible
Question 12
Correct
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?
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
Python is a relatively new programming language that was first released in 2008.
Select one:
True
False
Question 14
Correct
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
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
Select one:
True
False
Question 16
Correct
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".
e. 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
Select one:
True
False
Question 18
Correct
snippet 2)
var1=0
if var1==0:
var1=1
print(var1)
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.
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
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
b.
if var1==0 and var2==0:
# statements
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
Select one:
True
False
https://moodle.tu-ilmenau.de/mod/quiz/review.php?attempt=885&cmid=18593 11/11