Python_Questions_All_Chapters (1)
Python_Questions_All_Chapters (1)
Q1: Write a Python program to swap two variables without using a third variable.
Q3: Implement a function that converts a decimal number to binary and vice versa.
Q4: Write a Python script to reverse a string without using in-built functions.
Q5: Create a program that accepts a number as input and checks if it is a palindrome.
Q1: Write a program that takes a year as input and checks whether it is a leap year.
Q2: Implement a program to print the Fibonacci series up to 'n' terms using both loops and
recursion.
Q3: Write a Python script that prints prime numbers between 1 and 100.
Q5: Write a Python program to find the factorial of a number using recursion.
3. Functions
Q1: Write a Python function that returns the nth Fibonacci number.
Q3: Write a function that returns the reverse of a string using recursion.
Q4: Create a Python function that accepts any number of arguments and returns the sum of all
arguments.
Q5: Write a Python program to find the largest of three numbers using a function.
Q1: Write a Python program to find the second largest number in a list.
Q2: Implement a function that returns the intersection of two sets.
Q4: Implement a Python function that sorts a list of dictionaries by a specific key.
Q5: Create a program that removes duplicates from a list without using set.
5. Strings
Q2: Implement a function that counts the occurrences of each word in a string.
Q3: Write a Python program to find the longest common prefix in a list of strings.
6. File Handling
Q1: Write a Python program that reads a text file and counts the number of lines, words, and
characters.
Q2: Implement a program that reads a CSV file and prints its contents as a dictionary.
Q3: Write a function that writes a list of numbers to a file, and then reads the file and prints the
Q4: Create a Python program that merges the content of two text files into a new file.
Q5: Write a Python script to find and replace a specific word in a text file.
7. Object-Oriented Programming
Q1: Create a Python class that represents a bank account with methods for deposit and
withdrawal.
Q2: Implement a class that simulates a rectangle and includes methods for calculating the area
and perimeter.
Q3: Write a class that simulates a simple calculator with methods for addition, subtraction,
multiplication, and division.
Q4: Implement a Python class that simulates a student with attributes like name and grade, and a
Q5: Write a Python program that demonstrates inheritance by creating base and derived classes.
8. Regular Expressions
Q1: Write a Python script to validate email addresses using regular expressions.
Q2: Implement a program that uses a regular expression to extract phone numbers from a text
file.
Q3: Write a Python function that finds all occurrences of a specific pattern in a string using regular
expressions.
Q4: Create a program that validates dates in the format DD/MM/YYYY using regular expressions.
Q5: Implement a Python script that checks if a given string matches a specific regular expression
pattern.
9. Exception Handling
Q1: Write a Python function that handles divide-by-zero exceptions and prompts the user to enter
a valid denominator.
Q2: Create a program that raises a custom exception when a negative number is encountered.
Q3: Write a Python script that handles file not found errors when trying to open a file.
Q4: Implement a function that catches and handles multiple exceptions in a single block.
Q5: Create a Python program that prompts the user to input an integer and handles invalid input
exceptions.
Q1: Write a Python module with functions for arithmetic operations and import it into another
script.
Q2: Create a Python package that contains modules for handling different data structures like
Q3: Implement a script that imports the math module and calculates the square root, sine, and
cosine of a number.
Q4: Write a Python script that demonstrates the use of the random module to generate random
numbers.
Q5: Create a Python package that includes modules for basic geometric calculations (area,
perimeter, etc.).
Q1: Use the Pandas library to read a CSV file and calculate the average of a specific column.
Q2: Implement a Python script that uses the Matplotlib library to plot a graph of a given set of
data.
Q3: Create a Python program that scrapes data from a website using BeautifulSoup and stores it
in a CSV file.
Q4: Write a Python script that uses the Selenium library to automate a web form submission.
Q5: Implement a program that uses the Flask framework to create a basic web application with
one route.
Q1: Write a Python decorator that logs the execution time of a function.
Q2: Implement a generator that yields the Fibonacci sequence up to a given number.
Q3: Write a context manager class that handles opening and closing a file automatically.
Q4: Create a Python decorator that checks if a function's arguments are valid integers.
Q5: Implement a Python generator that produces an infinite sequence of prime numbers.
Q3: Create a Python program that finds the shortest path in a graph using Dijkstra's algorithm.
Q4: Write a Python script that implements a stack data structure with push and pop operations.