Python Essentials 1 - Module 2 Test Answers (2024)

Python Essentials 1 – Module 2 Test Answers

Python Essentials 1 Module 2 Completion – Module Test Quiz Answers

PE1: Module 2. Python Data Types, Variables, Operators, and Basic I/O Operations

1. The \n digraph forces the print() function to:

  • duplicate the character next to the digraph
  • break the output line
  • stop its execution
  • output exactly two characters: \ and n

Explanation: The digraph, called the newline character, causes the current line to end at the point indicated by the digraph, and creates a new line that starts right after it.

2. The meaning of the keyword parameter is determined by:

  • its position within the argument list
  • its connection with existing variables
  • the argument’s name specified along with its value
  • its value

Explanation: Keyword parameters (also called named parameters) are parameters that have values determined by a keyword name followed by an equals sign (=) and a default value assigned to that keyword name. An example of a keyword argument: def my_function(x=1):.

3. The value twenty point twelve times ten raised to the power of eight should be written as:

  • 20.12E8
  • 20.12*10^8
  • 20.12E8.0
  • 20E12.8

Explanation: Keeping in mind that Python chooses the most efficient format for presenting numbers, and the letter E is used to mean ten to the power of in scientific notation, the correct way of writing the number 20.12 × 108 is 20.12E8.

4. The 0o prefix means that the number after it is denoted as:

  • decimal
  • octal
  • binary
  • hexadecimal

Explanation: If an integer number is preceded by 0o or 0O, it will be treated as an octal value. For example: 0o246 is an octal number with a decimal value equal to 166.

If an integer number is preceded by 0x or 0X, it will be treated as a hexadecimal value. For example: 0x246 is a hexadecimal number with a decimal value equal to 582.

Finally, if an integer number is preceded by 0b or 0B, it will be treated as a binary value. For example: 0b1111 is a binary number with a decimal value equal to 15.

5. The ** operator:

  • does not exist
  • performs exponentiation
  • performs duplicated multiplication
  • performs floating-point multiplication

Explanation: The ** operator performs the exponent arithmetic in Python. It is also called the power operator.

6. The result of the following division:

1 / 1
  • cannot be predicted
  • cannot be evaluated
  • is equal to 1.0
  • is equal to 1

Explanation: The / operator is one of the two types of division operator in Python that divides its left operand by its right operand, and returns a floating-point value.

The // operator, called the floor division operator, performs a similar operation, but rounds down the result and returns an integer number.

7. Which of the following statements are true? (Select two answers)

  • The right argument of the % operator cannot be zero.
  • The result of the / operator is always an integer value.
  • The ** operator uses right-sided binding.
  • Addition precedes multiplication.

Explanation: The % operator (modulus) returns the remainder of a division, and because you cannot divide by zero, the right operand must be a non-zero number. Otherwise, a ZeroDivisionException will be raised.

The ** operator uses right-sided binding, which means the expression 2**2**3 is evaluated from right to left: 2**3 = 8, and 2**8 = 256.

8. Left-sided binding determines that the result of the following expression:

1 // 2 * 3

is equal to:

  • 0.0
  • 0
  • 0.16666666666666666
  • 4.5

Explanation: Left-sided binding means that the expression is evaluated from left to right: 1 // 2 = 0, and 0 * 3 = 0.

9. Which of the following variable names are illegal? (Select two answers)

  • and
  • true
  • True
  • TRUE

Explanation: True and and are Python keywords (reserved words), and they cannot be used as variable names. And since Python is case-sensitive, the names true and TRUE are perfectly legal, though not necessarily the best names.

10. The print() function can output values of:

  • any number of arguments (excluding zero)
  • not more than five arguments
  • any number of arguments (including zero)
  • just one argument

Explanation: The print() function can take no arguments at all (e.g. print()), three arguments (e.g. print("one", "two", "three"), or three thousand three hundred thirty three… (though we haven’t actually checked it!).

11. What is the output of the following snippet?

x = 1y = 2z = xx = yy = zprint(x, y)
  • 2 1
  • 1 1
  • 1 2
  • 2 2

Explanation: Let’s analyze this example:

– the value 1 is assigned to variable x, and variable x is initiated (so x = 1)
– the value 2 is assigned to variable y, and variable y is initiated (so y = 2)
– the value assigned to variable x is assigned to variable z, and variable z is initiated (so z = 1)
– the x variable is assigned the value which is assigned to variable y (so x = 2)
– the y variable is assigned the value which is assigned to variable z (so y = 1)
– the values ssigned to variables x and y are now printed, giving the following output: 2 1 (note: the print() function separates the outputted values with a whitespace)

12. What is the output of the following snippet if the user enters two lines containing 2 and 4 respectively?

x = input()y = input()print(x + y)
  • 4
  • 24
  • 2
  • 6

Explanation: Let’s analyze this example:

the input() function reads the arguments entered by the user (2 and 4 respectively) and converts them to strings,
variables x and y are assigned the strings inputted by the user,
the print() function outputs the result of the concatenation operation to the screen (the process of adding/merging strings): “2” + “4”; the + operator adds a string to another string, and outputs 24.

13. What is the output of the following snippet if the user enters two lines containing 2 and 4 respectively?

x = int(input())y = int(input()) x = x // yy = y // x print(y)
  • 8.0
  • the code will cause a runtime error
  • 2.0
  • 4.0

Explanation: Let’s analyze this example:
– the x variable is assigned the integer value of 2 (2 is inputted by the user, converted to a string by the input() function, and then converted to an integer by the int() function)
– the y variable is assigned the integer value of 4 (4 is inputted by the user, converted to a string by the input() function, and then converted to an integer by the int() function)
– an operation is performed resulting in the x variable being assigned the value of 0 (2 // 4=0)
– an operation is being performed, but a ZeroDivisionException is raised, because the // operator cannot accept 0 as its right operand. The program is terminated.

14. What is the output of the following snippet if the user enters two lines containing 2 and 4 respectively?

x = int(input())y = int(input()) x = x / yy = y / x print(y)
  • the code will cause a runtime error
  • 2.0
  • 8.0
  • 4.0

Explanation: Let’s analyze this example:

the x variable is assigned the integer value of 2 (2 is inputted by the user, converted to a string by the input() function, and then converted to an integer by the int() function)
the y variable is assigned the integer value of 4 (4 is inputted by the user, converted to a string by the input() function, and then converted to an integer by the int() function)
an operation is performed resulting in the x variable being assigned the value of 0.5 (2 / 4 = 0.5)
an operation is performed resulting in the y variable being assigned the value of 8.0 (4 / 0.5 = 8.0)
the value assigned to the y variable (8.0) is printed to the screen.

15. What is the output of the following snippet if the user enters two lines containing 11 and 4 respectively?

x = int(input())y = int(input()) x = x % yx = x % yy = y % x print(y)
  • 1
  • 2
  • 3
  • 4

Explanation: Let’s analyze this example:

the x variable is assigned the integer value of 11 (11 is inputted by the user, converted to a string by the input() function, and then converted to an integer by the int() function)
the y variable is assigned the integer value of 4 (4 is inputted by the user, converted to a string by the input() function, and then converted to an integer by the int() function)
an operation is performed resulting in the x variable being assigned the value of 3 (11 % 4 = 3)
an operation is performed resulting in the x variable being assigned the value of 0 (3 % 11 = 0)
an operation is performed resulting in the y variable being assigned the value of 1 (4 % 3 = 1)
the value assigned to the y variable (1) is printed to the screen.

16. What is the output of the following snippet if the user enters two lines containing 3 and 6 respectively?

x = input()y = int(input()) print(x * y)
  • 333333
  • 666
  • 36
  • 18

Explanation: Let’s analyze this example:

the x variable is assigned the value of “3” (3 is inputted by the user and converted to a string by the input() function)
the y variable is assigned the value of 6 (6 is inputted by the user, converted to a string by the input() function, and then converted to an integer by the int() function)
the print() function outputs the result of the following string multiplication: “3” * 6, that is 333333

17. What is the output of the following snippet?

z = y = x = 1print(x, y, z, sep='*')
  • x y z
  • 1 1 1
  • x*y*z
  • 1*1*1

Explanation: Let’s analyze the example:

the variables z, y, and x are declared and initialized, and the value 1 is assigned to each of them by using the mechanism of assigning the same value to multiple variables,
the values assigned to the three variables are printed to the screen and separated by the * symbol using the sep keyword argument.

18. What is the output of the following snippet?

y = 2 + 3 * 5.print(Y)
  • the snippet will cause an execution error
  • 17
  • 25.
  • 17.0

Explanation: Python is case-sensitive, so y and Y are two different variables. Since the program attempts to print to the screen a value associated with a variable that does not exist in the local namespace, Python doesn’t recognize it, and a NameError exception is raised.

19. What is the output of the following snippet?

x = 1 / 2 + 3 // 3 + 4 ** 2print(x)
  • 8
  • 17
  • 17.5
  • 8.5

Explanation: The principle of operator precedence (order of operations) takes effect here. Let’s see what happens here:

first, the 4 ** 2 expression is evaluated with 16 as the result,
second, the 1 / 2 expression is evaluated with 0.5 as the result,
third, the 3 // 3 expression is evaluated with 1 as the result,
finally, the three values are added (0.5 + 1 + 16), and the resulting value (17.5) is assigned to the x variable and printed to the screen.

20. What is the output of the following snippet if the user enters two lines containing 2 and 4 respectively?

x = int(input())y = int(input()) print(x + y)
  • 4
  • 2
  • 24
  • 6

Explanation: The values 2 and 4 are inputted by the user, converted from strings to integers, and assigned to the x and y variables respectively. The print() function outputs the result of integer addition (2 + 4) to the screen.

Python Essentials 1 - Module 2 Test Answers (2024)

FAQs

How do I pass the Python certification exam? ›

Practice is key to mastering Python concepts. Make sure to work on coding exercises regularly and take mock tests to assess your knowledge. This will help you identify your weak areas and focus on improving them before the actual exam. Before the exam, familiarize yourself with the exam format and syllabus.

What is the most important difference between integer and floating point numbers lies in fact? ›

An integer (more commonly called an int) is a number without a decimal point. A float is a floating-point number, which means it is a number that has a decimal place. Floats are used when more precision is needed.

What is module 2 in Python? ›

This module is designed to introduce you to the essential elements of Python. We will begin by studying the basic types of objects that are built-in to Python, which will enable us to work with numbers, text, and containers that can store a collection of objects.

What is machine code in Python for Cisco? ›

Machine code, also known as 'machine language' or 'native code,' is the elemental language of computers. It is read by the computer's central processing unit (CPU), is composed of digital binary numbers and looks like a very long sequence of zeros and ones.

What is the hardest question in Python? ›

Advanced Python interview questions
  • How do I access a module written in Python from C? ...
  • How do you reverse a list in Python? ...
  • What does break and continue do in Python? ...
  • Can break and continue be used together? ...
  • What will be the output of the code below? ...
  • Explain generators vs iterators.

Is the Python certification exam hard? ›

The difficulty level of the certification should match your current proficiency in Python. For beginners, diving into an advanced certification might prove daunting, and conversely, seasoned professionals might find beginner certifications too rudimentary.

Which is bigger, float or int? ›

Apparently, float and int take up the same amount of bytes, 4. However, according to this page, has its limit on 2,147,483,647, while float supports numbers as high as 3.4E+38. While the integer overflows, as expected, the float returns a relatively precise value (not completely precise, but close to my input).

What is float() in Python? ›

Float is a function or reusable code in the Python programming language that converts values into floating point numbers. Floating point numbers are decimal values or fractional numbers like 133.5, 2897.11, and 3571.213, whereas real numbers like 56, 2, and 33 are called integers.

Should you use float or int? ›

If you are dealing with whole numbers or require exact precision, use integers. If the data involves decimal parts or decimal calculations, use floats.

What is the main module in Python? ›

What is the __main__ Module in Python? The __main__ module is a special environment where the top-level code is executed. If you run a script directly, Python sets the __name__ attribute of the script to __main__ . This means that the script is the main program being executed.

How many libraries are there in Python? ›

Python has a vast and continuously growing ecosystem of libraries. The total numbers of Python are more than 137000 libraries. All these libraries are used in machine learning, data science, data manipulation and visualization, and more.

How many modules are in Python? ›

The Python standard library contains well over 200 modules, although the exact number varies between distributions.

Which programming language cannot be replaced by AI? ›

Artificial intelligence (AI) cannot completely replace Java backend development or any other software engineering discipline.

What is the difference between a compiler and an interpreter? ›

Compiler: A compiler translates code from a high-level programming language into machine code before the program runs. Interpreter: An interpreter translates code written in a high-level programming language into machine code line-by-line as the code runs.

How does Python turn into machine code? ›

When Python code is run, it is first compiled into bytecode and executed with the CPython interpreter (unless you are using some other implementation of Python). The CPython interpreter is compiled to machine code, which will interpret the Python code.

How many questions are on the Python certification exam? ›

Exam overview
Exam fee:$95
Number of questions:Adaptive, 60 on average
Requirement to pass:Minimum 40% - Intermediate level
Time limit:60 minutes
Number of attempts to pass:Three
8 more rows

How to prepare for a Python exam? ›

Take practice exams: Practice exams can help you identify your strengths and weaknesses and focus your study efforts. You can find practice exams online or in Python programming books. Join a study group: Joining a study group or working with a study partner can help you stay motivated and accountable.

Top Articles
Latest Posts
Article information

Author: Dan Stracke

Last Updated:

Views: 5474

Rating: 4.2 / 5 (43 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Dan Stracke

Birthday: 1992-08-25

Address: 2253 Brown Springs, East Alla, OH 38634-0309

Phone: +398735162064

Job: Investor Government Associate

Hobby: Shopping, LARPing, Scrapbooking, Surfing, Slacklining, Dance, Glassblowing

Introduction: My name is Dan Stracke, I am a homely, gleaming, glamorous, inquisitive, homely, gorgeous, light person who loves writing and wants to share my knowledge and understanding with you.