0% found this document useful (0 votes)
22 views

Python_Questions_All_Chapters (1)

Dfh hjye iooop

Uploaded by

Shivam Keshari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Python_Questions_All_Chapters (1)

Dfh hjye iooop

Uploaded by

Shivam Keshari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Python Questions: Basic to Advanced

1. Data Types and Variables

Q1: Write a Python program to swap two variables without using a third variable.

Q2: Explain mutable and immutable data types with examples.

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.

2. Control Flow (if, for, while, etc.)

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.

Q4: Implement a function that checks if a given number is an Armstrong number.

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.

Q2: Implement a Python function to calculate the LCM of two numbers.

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.

4. Lists, Tuples, Sets, and Dictionaries

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.

Q3: Write a program to convert a list of tuples into a dictionary.

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

Q1: Write a program that checks if a string is a palindrome.

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.

Q4: Implement a function to reverse the words in a given sentence.

Q5: Create a function that removes all vowels from a string.

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

sum of the numbers.

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

method to display the details.

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.

10. Modules and Packages

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

lists, stacks, and queues.

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.).

11. Libraries and Frameworks

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.

12. Advanced Python (Decorators, Generators, Context Managers)

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.

13. Algorithms and Data Structures


Q1: Write a Python function that implements binary search on a sorted list.

Q2: Implement a Python script to sort a list using merge sort.

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.

Q5: Implement a queue using two stacks in Python.

You might also like