Python Programming Exam Questions
24 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Which operator is NOT considered an arithmetic operator in Python?

  • Multiplication (*)
  • Exponentiation (**) or Concatenation (.) (correct)
  • Division (/)
  • Addition (+)
  • Logical operators can be used to combine multiple Boolean expressions.

    True (A)

    What are the basic data types available in Python?

    int, float, str, list, tuple, dict, set

    In Python, a ________ is used to store values for later use.

    <p>variable</p> Signup and view all the answers

    Match the following operators with their respective descriptions:

    <p>Arithmetic Operators = Used for mathematical calculations Comparison Operators = Used to compare two values Logical Operators = Used to combine conditional statements Bitwise Operators = Used to perform operations on binary representations</p> Signup and view all the answers

    Which function would you use to split a string into a list of words?

    <p>split() (C)</p> Signup and view all the answers

    Strings in Python are mutable, meaning they can be changed after creation.

    <p>False (B)</p> Signup and view all the answers

    How would you check if a year is a leap year in Python?

    <p>By using the condition: year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)</p> Signup and view all the answers

    Which method of the os module would you use to change the current working directory?

    <p>chdir() (B)</p> Signup and view all the answers

    The os.path module provides methods to manipulate file and directory paths.

    <p>True (A)</p> Signup and view all the answers

    What is the primary use of the isfile() method in the os.path module?

    <p>To check if a specified path is a file.</p> Signup and view all the answers

    The _______ method in os module can be used to remove an empty directory.

    <p>rmdir</p> Signup and view all the answers

    Match the following os module methods with their descriptions:

    <p>chdir() = Changes the current working directory getcwd() = Returns the current working directory listdir() = Lists files in a directory walk() = Generates the file names in a directory tree</p> Signup and view all the answers

    Which of the following formats is characterized by its use of commas to separate values?

    <p>CSV (C)</p> Signup and view all the answers

    Files can be deleted using the walk() method of the os module.

    <p>False (B)</p> Signup and view all the answers

    Describe the diamond problem in Python programming.

    <p>The diamond problem occurs in multiple inheritance when a class inherits from two classes that have a common ancestor, leading to ambiguity in method resolution.</p> Signup and view all the answers

    What does the Python program need to count in a given string?

    <p>Vowels, consonants, and blanks (B)</p> Signup and view all the answers

    Python can add two matrices together.

    <p>True (A)</p> Signup and view all the answers

    What is the purpose of the zip() function in Python?

    <p>To combine two or more iterables into tuples.</p> Signup and view all the answers

    The function used to calculate the __________ of a list of numbers is called variance.

    <p>variance</p> Signup and view all the answers

    Match the following Python functions with their purposes:

    <p>intersection() = Find common elements between sets union() = Combine all elements from multiple sets issubset() = Check if one set is a subset of another difference() = Find elements in one set that are not in another</p> Signup and view all the answers

    Which of these is NOT a characteristic of tuples?

    <p>Mutable (D)</p> Signup and view all the answers

    The average of all numbers is referred to as the mode.

    <p>False (B)</p> Signup and view all the answers

    Explain what is meant by 'Pythonic code.'?

    <p>Pythonic code is code that follows Python's conventions and idiomatic practices, making it clear, readable, and efficient.</p> Signup and view all the answers

    Flashcards

    Arithmetic Operators in Python

    Operators used for mathematical operations like addition, subtraction, multiplication, and division.

    Assignment Operators in Python

    Used to assign values to variables.

    Comparison Operators in Python

    Operators used to compare values (e.g., equal to, greater than).

    Python Data Types

    Different kinds of data Python can handle (e.g., numbers, text).

    Signup and view all the flashcards

    Python Identifiers

    Names given to variables, functions, and other program elements.

    Signup and view all the flashcards

    Leap Year Check (Python)

    Determining if a year is a leap year (divisible by 4, not 100 unless divisible by 400).

    Signup and view all the flashcards

    String Immutability

    Strings in Python cannot be changed after creation.

    Signup and view all the flashcards

    Reverse a Number (Python)

    Reversing the digits of a number and calculating the sum of the reversed digits

    Signup and view all the flashcards

    Vowel Counting in a String

    Write a Python program to count the number of vowels (a, e, i, o, u) in a given string.

    Signup and view all the flashcards

    Consonant Counting in a String

    Write a Python program to count the number of consonants in a given string.

    Signup and view all the flashcards

    Blank Space Counting in a String

    Write a Python program to count the number of blank spaces in a given string.

    Signup and view all the flashcards

    Adding Matrices in Python

    Write a Python program to add two matrices of the same dimensions.

    Signup and view all the flashcards

    Transpose of a Matrix

    Write a Python program to find the transpose of a matrix. The transpose of a matrix is obtained by interchanging its rows and columns.

    Signup and view all the flashcards

    Sum of Positive and Negative Numbers

    Write a Python program to find the sum of positive and negative numbers from a list of five integers.

    Signup and view all the flashcards

    Average and Above Average

    Write a Python program to find the average of all numbers in a given list and then find the numbers that are above average.

    Signup and view all the flashcards

    Mean, Variance, and Standard Deviation

    Write a Python program to calculate the mean, variance, and standard deviation of a list of numbers.

    Signup and view all the flashcards

    Python os Module: Purpose

    The os module in Python provides a way to interact with your computer's operating system. It offers functions for file and directory management, process handling, and environmental variables. It's a crucial tool for working with files and system resources.

    Signup and view all the flashcards

    Python os.path Module: Tasks

    The os.path module in Python specifically focuses on file and directory paths. It provides functions for manipulating path components like getting the directory of a file, combining paths, and comparing paths.

    Signup and view all the flashcards

    Python os.path.isfile()

    This function checks if a given path refers to an existing file. It returns True if it's a file, False otherwise.

    Signup and view all the flashcards

    Python os.path.isdir()

    This function checks if a given path refers to an existing directory. It returns True if it's a directory, False otherwise.

    Signup and view all the flashcards

    Python os.path.abspath()

    This function converts a path to its absolute form. An absolute path starts from the root directory of the file system.

    Signup and view all the flashcards

    Python os.path.relpath()

    This function calculates the relative path between two given paths. It tells you how to get from one directory to another.

    Signup and view all the flashcards

    Python os.path.dirname()

    This function extracts the directory name from a given path. It gives you the parent folder of a file or directory.

    Signup and view all the flashcards

    Polymorphism in Python

    Polymorphism in Python allows objects of different classes to be treated the same way, based on their shared methods. It's like having different shaped keys that can all unlock the same door.

    Signup and view all the flashcards

    Study Notes

    Python Programming Exam Questions

    • Question 1: Describe arithmetic, assignment, comparison, logical, and bitwise operators in detail with examples.
    • Question 1: Explain identifiers, keywords, statements, expressions, and variables in Python, providing examples.
    • Question 1: Explain basic data types in Python with examples.
    • Question 2a: Write a Python program to reverse a number, find the sum of its digits, and prompt the user for input.
    • Question 2b: Write a Python program to check if a given year is a leap year.
    • Question 2c: Write a Python program to find the greatest common divisor (GCD) of two positive numbers.
    • Question 3a: Write a Python code to determine if a given string is a palindrome using slicing.
    • Question 3b: Explain the join() and split() string methods with examples, and describe immutability of strings with examples.
    • Question 3c: Write a Python program to calculate the total number of vowels, consonants, and blanks in a string.
    • Question 4a: Write a Python program to add two matrices, including finding the transpose of the result.
    • Question 4b: Write a Python program that takes five integers, calculates the sum of negative numbers, positive numbers, their average, and numbers above average.
    • Question 4c: Write a Python program to calculate the mean, variance, and standard deviation of a list of numbers.
    • Question 5a: Discuss the relationship between tuples and lists, and between tuples and dictionaries in detail.
    • Question 5b: Write a Python program to swap two numbers without using a temporary variable.
    • Question 5c: Write a program that accepts a sentence and determines the count of digits, uppercase letters, and lowercase letters.
    • Question 6a: Write a Pythonic program to sort names alphabetically without using the sort() function.
    • Question 6b: Discuss the zip() function with an example.
    • Question 6c: Show how to use the intersection(), union(), subset(), difference(), update(), and discard() Set methods with examples.
    • Question 7a: Discuss special characters \d, \w, \b, {m, n}, \, and ? in detail.
    • Question 7b: Write a Python program to delete all files and subdirectories from an Extinct_Animals directory
    • Question 7c: Describe the Python os and os.path modules, including methods chdir(), rmdir(), walk(), listdir(), getcwd(), isfile(), abspath(), relpath(), dirname(), splitext(), and getmtime().
    • Question 8a: Describe the characteristics of the CSV format.
    • Question 8b: Write a Python program to write data to a CSV file (given example data including Category, Winner, Film, and Year).
    • Question 9a: Write a Python program, using polymorphism, to calculate the area and perimeter of different shapes.
    • Question 9b: Illustrate the “diamond problem” in Python programming with an example.
    • Question 10a: Write a Python program to demonstrate the construction of Method Resolution Order.
    • Question 10b: Create two rectangle objects, write a Python program to check if the area of the first rectangle is greater than the second using the overloading > operator.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    Description

    This quiz covers various aspects of Python programming, including operators, data types, and basic programming tasks. It is designed to test knowledge through both theoretical questions and practical coding exercises. Perfect for students looking to evaluate their understanding of Python basics and coding skills.

    More Like This

    Level Up Your Python Coding
    5 questions
    Python Lists and Data Types Quiz
    5 questions
    Python Basics Quiz
    39 questions

    Python Basics Quiz

    OrderlySakura avatar
    OrderlySakura
    Use Quizgecko on...
    Browser
    Browser