Python Essentials 2 - Module 2 Test Answers (Completion) (2024)

November 6, 2022Python Essentials 2Leave a comment

Python Essentials 2 Module 2 Completion – Module Test Answers

Python Essentials 2: PE2: Module 2. Strings, String and List Methods, Exceptions test Answers full new questions

1. Entering the try: block implies that:

  • none of the instructions from this block will be executed
  • the block will be omitted
  • all of the instructions from this block will be executed
  • some of the instructions from this block may not be executed

Explanation:

Remember that the instructions inside a try block are executed sequentially. If an instruction generates an exception, the execution jumps to the except statements. Therefore, the remaining instructions within the try block are not executed.

2. The unnamed except: block:

  • must be the first one
  • can be placed anywhere
  • must be the last one
  • cannot be used if any named block has been used

Explanation:

The excepts within a try expect block should be listed from the specific exceptions to the general exceptions. This assures that in case of an error, the error will fall under the suitable exception. The unnamed exception must be the last exception listed because it is the most general exception.

3. The top‑most Python exception is called:

  • Exception
  • PythonException
  • TopException
  • BaseException

Explanation:

Remember that the BaseException class is, as the name suggests, the base class for all built-in exceptions in Python.

4. The following statement:

assert var == 0
  • has no effect
  • will stop the program when var != 0
  • will stop the program when var == 0
  • is erroneous

Explanation:

Remember that the assert keyword tests if a condition is true. If it is not, the program will raise an AssertionError.

5. What is the expected output of the following code?

try: print("5"/0)except ArithmeticError: print("arith")except ZeroDivisionError: print("zero")except: print("some")
  • zero
  • arith
  • 0
  • some

Explanation:

Let’s analyze this code snippet:

  • The print function inside the try block is executed.
  • If you look closely, “5” is a string, and it is divided by an integer zero.
  • No ArithmeticError nor ZeroDivisionError is raised.
  • Instead, a TypeError exception is raised, which will fall under the nameless except.
  • The word some is printed in the console.

6. Which of the following are examples of built-in concrete Python exceptions? (Select two answers)

  • IndexError
  • ArithmeticError
  • BaseException
  • ImportError

Explanation: Remember that concrete exceptions in Python are build-in exceptions that inherit directly from the Exception class. IndexError and ImportError are such cases.

7. ASCII is:

  • short for American Standard Code for Information Interchange
  • a standard Python module name
  • a predefined Python variable name
  • a character name

Explanation: Remember that ASCII stands for American Standard Code for Information Interchange. It is a 7-bit character code developed in the 19-60s to represent English-language characters.

8. UTF‑8 is:

  • a synonym for byte
  • the 9th version of the UTF standard
  • a form of encoding Unicode code points
  • a Python version name

Explanation: Remember that UTF-8 is the most popular type of Unicode encoding. It uses 1 bit for English characters, 2 bits for Latin and Middle Eastern characters, and 3 bits for Asian characters.

9. UNICODE is a standard:

  • like ASCII, but much more expansive
  • used by coders from universities
  • honored by the whole universe
  • for coding floating-point numbers

Explanation: Remember that UNICODE is a universal character encoding standard. It supports characters from all the languages in the world.

10. The following code:

x = '\''print(len(x))prints:
  • 3
  • 1
  • 20
  • 2

Explanation:

Let’s analyze this code snippet:

  • A string variable named x is defined.
  • The first and last single quotes delimit the contents within the variable, and are not part of the content.
  • The backslash is the escape character, which also does not count as part of the content.
  • The single quote after the backslash is the only character that is part of the variable contents.
  • Using the print function, the character length of the variable is shown in the console, and the answer is 1.

11. The following code:

print(ord('c') - ord('a')) prints:
  • 0
  • 3
  • 1
  • 2

Explanation: The ord() function in Python returns the Unicode code of the given character. A lower-case c returns 99, and a lower-case a returns 97. Therefore, 99 minus 97 equals 2. This is what is printed in the console.

12. The following code:

print(chr(ord('z') ‑ 2)) prints:
  • a
  • y
  • z
  • x

Explanation: The ord() function in Python returns the Unicode code of the given character. A lower-case z returns a 122. Then 2 is subtracted from 122, which results in 120. Finally, the 120 value is converted to its Unicode character x using the chr() function. So, x is printed in the console.

13. The following code:

print(3 * 'abc' + 'xyz') prints:
  • abcabcxyzxyz
  • abcabcabcxyz
  • xyzxyzxyzxyz
  • abcxyzxyzxyz

Explanation:

The * and + operators replicate and concatenate when used with strings. The first operation 3 * ‘abc’ returns a string that contains abcabcabc. Then the second operation + ‘xyz’ concatenates xyz to the previous string. The resulting string abcabcabcxyz is printed in the console.

14. The following code:

print('Mike' > "Mikey") prints:
  • True
  • 1
  • 0
  • False

Explanation:

The > operator, when used with strings, compares character for character. This means characters in the same positions are compared from both the strings. Since Mike is shorter than Mikey, it cannot be greater. Therefore, the answer is False.

15. The following code:

print(float("1, 3"))
  • prints 1.3
  • prints 13
  • prints 1,3
  • raises a ValueError exception

Explanation:

The float function tries to convert the 1, 3 string into a floating-point value. Since it contains a comma and a whitespace, a ValueError exception is raised because it cannot be converted.

Python Essentials 2 - Module 2 Test Answers (Completion) (2024)

FAQs

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 the top most Python exception called? ›

Python has a number of built-in exceptions, such as the well-known errors SyntaxError, NameError, and TypeError. These Python Exceptions are thrown by standard library routines or by the interpreter itself.

What does entering the try block implies that? ›

Entering the try: block implies that:

all of the instructions from this block will be executed.

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.

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.

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 the most wanted holder in Python? ›

Most-wanted-holder A variable holding the best or otherwise most appropriate value encountered so far. (For example the biggest value so far.) Gatherer A variable accumulating the effect of a series of individual values, for example a running-total.

What is the most stable Python version now? ›

Stable Releases
  • Python 3.12.5 - Aug. 6, 2024. ...
  • Python 3.12.4 - June 6, 2024. Download Gzipped source tarball. ...
  • Python 3.12.3 - April 9, 2024. Download Gzipped source tarball. ...
  • Python 3.11.9 - April 2, 2024. ...
  • Python 3.10.14 - March 19, 2024. ...
  • Python 3.9.19 - March 19, 2024. ...
  • Python 3.8.19 - March 19, 2024. ...
  • Python 3.11.8 - Feb.

When should a try except block be used? ›

The reason to use try/except is when you have a code block to execute that will sometimes run correctly and sometimes not, depending on conditions you can't foresee at the time you're writing the code.

Can we use try with resources without catch and finally? ›

As I learned from my OCP Study Guide, the catch and the finally block are optional with try-with-ressources statement.

What happens when a try block fails? ›

The code in the try block is executed first, and if it throws an exception, the code in the catch block will be executed. The code in the finally block will always be executed before control flow exits the entire construct.

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.

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 does Python detect modules? ›

Python looks for modules in “sys.

Python has a simple algorithm for finding a module with a given name, such as a_module . It looks for a file called a_module.py in the directories listed in the variable sys. path .

What is the difference between integer and floating literal? ›

An integer literal can also have a suffix that is a combination of U and L, for unsigned and long, respectively. The suffix can be uppercase or lowercase and can be in any order. A floating-point literal has an integer part, a decimal point, a fractional part, and an exponent part.

What is the difference between integer and floating constant? ›

Answer: (a)Integer Constants represent whole number values like 2, -16, 18246, 24041973, etc. Floating Constants represent fractional numbers like 3.14159, -14.08, 42.0, 675.238, etc.

Why is it necessary to treat integer and floating-point numbers so differently? ›

Integers and floats are represented differently internally and they have separate circuity to perform mathematical operations. Integer arithmetic is a lot faster than floating point arithmetic and take up less space, so it's best to use them when you can.

What are the advantages of floating-point numbers over integers? ›

Floating-point numbers have two advantages over integers. First, they can represent values between integers. Second, because of the scaling factor, they can represent a much greater range of values.

Top Articles
9 of the world's most beautiful lakes and what to do there
Lc-data in Zevenaar Zorgt dat je meer weet...
Jps Occupational Health Clinic
Tony's Delicatessen & Fresh Meats
Jeff Bezos Lpsg
Comenity Pay Ns Web Payment
Frank 26 Forum
Tmobile Ipad 10Th Gen
Congdon Heart And Vascular Center
Understanding Pickleball Court Dimensions: Essential Guide
Dr Paul Memorial Medical Center
Tamara Lapman
The Land Book 9 Release Date 2023
Craigslist.com Seattle Wa
Espn Major League Baseball Standings
Cherry Spa Madison
Lucifer Season 1 Download In Telegram In Tamil
Craigslist Westchester Cars For Sale By Owner
Hotleak.vip
My Big Fat Greek Wedding 3 Showtimes Near Regal Ukiah
Her Triplet Alphas Chapter 22
Waitlistcheck Sign Up
Brake Masters 208
Aussiebigdaddik
Frederik Zuiderveen Borgesius on LinkedIn: Amazingly quick work by Arnoud💻 Engelfriet! Can’t wait to dive in.
7 Little Johnstons Alex Died Full Episode
Alloyed Trident Spear
Drug Stores Open 24Hrs Near Me
Hally Vogel
Numerous people shot in Kentucky near Interstate 75, officials say | CNN
Retire Early Wsbtv.com Free Book
Heyimbee Forum
Lox Club Gift Code
Virtualrewardcenter.com/Activate
Courtney Lynn Playboy
Antique Wedding Favors
Ixl Ld Northeast
Natalya's Vengeance Set Dungeon
Southeast Ia Craigslist
Osceola County Addresses Growth with Updated Mobility Fees
Swissport Timecard
Wie blocke ich einen Bot aus Boardman/USA - sellerforum.de
Ces 2023 Badge Pickup
Texas State Academic Probation
Tapana Movie Online Watch 2022
Blow Dry Bar Boynton Beach
Sparkle Nails Phillipsburg
Drew Gulliver Bj
Dungeon Family Strain Leafly
Criagslist Orlando
What Time Does Walmart Auto Center Open
Redbox Walmart Near Me
Latest Posts
Article information

Author: Golda Nolan II

Last Updated:

Views: 5500

Rating: 4.8 / 5 (58 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Golda Nolan II

Birthday: 1998-05-14

Address: Suite 369 9754 Roberts Pines, West Benitaburgh, NM 69180-7958

Phone: +522993866487

Job: Sales Executive

Hobby: Worldbuilding, Shopping, Quilting, Cooking, Homebrewing, Leather crafting, Pet

Introduction: My name is Golda Nolan II, I am a thoughtful, clever, cute, jolly, brave, powerful, splendid person who loves writing and wants to share my knowledge and understanding with you.