PE1 : Python Essentials 1 – Module 1 Test Exam Answers



PE1 : Python Essentials 1 – Module 1 Test Exam Answers

Python Essentials 1 (PE1) – Module 1 Test Exam Answers are designed to help learners grasp the foundational concepts of Python programming effectively. This module covers key topics such as Python program structure, basic syntax, variables, data types, and simple input/output operations. By reviewing these exam answers, students can solidify their understanding of the module’s content, practice problem-solving skills, and prepare for more advanced topics in Python programming.

  1. What is true about compilation? (Select two answers)

    • Both you and user must have the compiler to run your code
    • The code is converted directly into machine code executable by the processor
    • It tends to be faster than interpretation
    • It tends to be than interpretation
      Explanation & Hints:

      The correct answers are:

      1. The code is converted directly into machine code executable by the processor
        • Compilation translates the entire source code into machine code, which is then directly executed by the processor.
      2. It tends to be faster than interpretation
        • Compiled code generally runs faster because it has already been translated into machine code, eliminating the need for real-time interpretation.
  2. What is CPython?

    • It’s the default, reference implementation of the C language, written in Python
    • It’s a programming language that is a supperset of the Python, designed to produce C-like performance with code written in Python
    • It’s the default, reference implementation of Python, written in the C language
    • It’s a programming that is a superset of the C language, designed to produce Python-like performance with code written in C
    • Explanation & Hints:

      The correct answer is:

      It’s the default, reference implementation of Python, written in the C language

      Explanation:
      CPython is the original and most widely used implementation of the Python programming language. It is written in C and serves as the reference implementation that defines the Python language specification.

  3. What are the four fundamental elements that make a language?

    • An alphabet, morphology, phonetics, and semantics
    • An alphabet, a lexis, a syntax, and semantics
    • An alphabet, a lexis, phonetics, and semantics
    • An alphabet, phonetics, phonology, and semantics
    • Explanation & Hints:

      The correct answer is:

      An alphabet, a lexis, a syntax, and semantics

      Explanation:
      The four fundamental elements that make up a language are:

      1. Alphabet: The set of symbols or characters used to write the language.
      2. Lexis: The vocabulary or set of words in the language.
      3. Syntax: The rules for structuring sentences and expressions in the language.
      4. Semantics: The meaning conveyed by the words and structures in the language.
  4. What do you call a file containing a program written in a high-level programming language?

    • A machine file
    • A code file
    • A target file
    • A source file
    • Explanation & Hints:

      The correct answer is:

      A source file

      Explanation:
      A file containing a program written in a high-level programming language is called a source file because it is the source code that needs to be compiled or interpreted to create an executable or to run the program.

  5. What do you call a command-line interpreter which lets you interact with your OS and execute Python commands and scripts?

    • An editor
    • A console
    • A compiler
    • Jython
    • Explanation & Hints:

      The correct answer is:

      A console

      Explanation:
      A console is a command-line interpreter that allows you to interact with your operating system and execute Python commands and scripts. It provides an environment for running Python code interactively or running Python scripts directly.

  6. What is the expected behavior of the following program?

    print("Hello!")
    • The program will output ("Hello!") to the screen
    • The program will generate an error message on the screen
    • The program will output  Hello! to the screen
    • The program will output "Hello!" to the screen
    • Explanation & Hints:

      The correct answer is:

      The program will output Hello! to the screen

      Explanation:
      The print function in Python outputs the string provided within its parentheses to the screen. Strings are enclosed in quotes ("" or '') to indicate that they are text, but the quotes themselves are not displayed in the output. Therefore, the program will display the text Hello! without quotes.

  7. What is the best definition of a script?

    • It’s an error message generated by the interpreter
    • It’s an error message generated by the compiler
    • It’s a text file that contains which make up a Python program
    • It’s a text file that contains sequences of zeroes and ones
    • Explanation & Hints:

      The correct answer is:

      It’s a text file that contains which make up a Python program

      Explanation:
      A script is a text file that contains a sequence of instructions written in a programming language like Python. These instructions (code) can be executed by an interpreter to perform specific tasks. Scripts are often used for automating tasks, data processing, or running programs.

  8. What is the expected behavior of the following program?

    prin("Goodbye!")
    • The program will output Goodbye! to the screen
    • The program will generate an error message on the screen 
    • The program will output("Goodbye!")
    • The program will output "Goodbye!"
    • Explanation & Hints:

      The correct answer is:

      The program will generate an error message on the screen

      Explanation:
      The function name prin is incorrect because Python requires the exact syntax for function calls. The correct function name is print. Since prin is not defined, the program will raise a NameError indicating that prin is not recognized.

  9. What is machine code?

    • A high-level programming language consisting of instruction lists that humans can read and understand
    • A medium-level programming language consisting of the assembly code designed for the computer processor
    • A low-level programming language consisting of binary digits/bits that the computer reads and understands
    • A low-level programming language consisting of hexadecimal digits that make up high-level language instructions
    • Explanation & Hints:

      The correct answer is:

      A low-level programming language consisting of binary digits/bits that the computer reads and understands

      Explanation:
      Machine code is the lowest level of programming language, consisting of binary digits (0s and 1s) that a computer’s processor directly executes. Unlike high-level or assembly languages, machine code is not intended to be human-readable. It represents instructions in a form that the hardware can process directly.

  10. Select the true statements. (Select two answers)

    • Python is a good choice for creating and executing tests for applications
    • Python 3 is backwards compatible with Python 2
    • Python is a good choice for low-level programming e.g., when you want to implement an effective driver
    • Python is free, open-source, and multiplatform
    • Explanation & Hints:

      The correct answers are:

      1. Python is a good choice for creating and executing tests for applications
        • Python’s simplicity, readability, and extensive libraries make it an excellent choice for creating and executing tests for various applications.
      2. Python is free, open-source, and multiplatform
        • Python is free to use, open-source, and available on multiple platforms (Windows, macOS, Linux, etc.), making it accessible and versatile for a wide range of developers.

      Explanation of incorrect options:

      • Python 3 is backwards compatible with Python 2
        This is incorrect because Python 3 introduced changes that are not backwards compatible with Python 2, requiring adjustments to code when migrating.
      • Python is a good choice for low-level programming e.g., when you want to implement an effective driver
        This is incorrect because Python is a high-level language and not typically used for low-level programming tasks such as writing drivers, which are better suited for languages like C or Assembly.