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

    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()</p> Signup and view all the answers

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

    <p>False</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()</p> Signup and view all the answers

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

    <p>True</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</p> Signup and view all the answers

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

    <p>False</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</p> Signup and view all the answers

    Python can add two matrices together.

    <p>True</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</p> Signup and view all the answers

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

    <p>False</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

    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

    Use Quizgecko on...
    Browser
    Browser