Python Practice Questions, Exercises of Computer Science

Regular Python practice problems are one of the fastest ways to move from “I understand the syntax” to “I can actually build and solve real problems.” Python is one of the most beginner-friendly and versatile programming languages in the world. From web development and automation to data science, artificial intelligence, cybersecurity, and software engineering, Python has applications in almost every major technology domain. However, simply learning Python syntax is not enough to become proficient. The real growth happens when you consistently solve Python practice problems. Practice problems sharpen logical thinking, improve coding fluency, strengthen debugging skills, and prepare you for real-world development and technical interviews.

Typology: Exercises

2024/2025

Uploaded on 02/24/2026

unknown user
unknown user 🇮🇳

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Create a Python program that accepts two numbers from the user and performs basic arithmetic
operations (addition, subtraction, multiplication, division). Display the results with appropriate
labels.
1. Use input() to read numbers.
2. Use variables and expressions.
3. Handle division carefully (no division by zero).
Write a Python program that prints a famous quote, ensuring the quote and the author's name
are properly formatted with the use of quotation marks and escape characters.
Albert Einstein once said, "Imagination is more important than knowledge."
1. Use proper use of quotes and escape sequences (\").
2. Use string variables to store the quote and author separately.
Ask the user for a number and determine whether it is even or odd. Display an appropriate
message.
1. Use if-else decision-making statements.
2. Use modulus operator (%) for the check.
3. Print clear output.
Create a Python program that accepts a student's score and prints their grade based on the
following:
90 and above: A
8089: B
7079: C
6069: D
Below 60: F
Use if-elif-else statements.
Validate that the score entered is between 0 and 100.
pf3
pf4
pf5
pf8

Partial preview of the text

Download Python Practice Questions and more Exercises Computer Science in PDF only on Docsity!

Create a Python program that accepts two numbers from the user and performs basic arithmetic operations (addition, subtraction, multiplication, division). Display the results with appropriate labels.

  1. Use input() to read numbers.
  2. Use variables and expressions.
  3. Handle division carefully (no division by zero). Write a Python program that prints a famous quote, ensuring the quote and the author's name are properly formatted with the use of quotation marks and escape characters. Albert Einstein once said, "Imagination is more important than knowledge."
  4. Use proper use of quotes and escape sequences (").
  5. Use string variables to store the quote and author separately. Ask the user for a number and determine whether it is even or odd. Display an appropriate message.
  6. Use if-else decision-making statements.
  7. Use modulus operator (%) for the check.
  8. Print clear output. Create a Python program that accepts a student's score and prints their grade based on the following: 90 and above: A 80 – 89: B 70 – 79: C 60 – 69: D Below 60: F Use if-elif-else statements. Validate that the score entered is between 0 and 100.

Write a Python program that accepts a string from the user and prints the reversed version of the string.

  1. Use slicing ([::-1]).
  2. Also display the original string length using len(). Ask the user to input a string and check whether the string is a palindrome (reads the same forwards and backwards).
  3. Ignore case (use .lower()).
  4. Use decision-making (if-else) based on comparison. Write a Python program that counts the number of words in a user-entered sentence.
  5. Use the split() method.
  6. Print the total word count. Create a program that asks the user to input a sentence and a character, then finds and prints:
  7. How many times that character appears (count() method).
  8. The first position where the character occurs (find() method). Create a list of 5 numbers entered by the user. Perform the following:
  9. Display the list.
  10. Add a new number to the list.
  11. Sort the list in ascending order.
  12. Remove a number entered by the user. Use append(), sort(), and remove() methods. Create a tuple with 5 user-entered elements and perform:
  13. Find the maximum and minimum values.
  14. Find the sum of all elements.
  15. Print the second and fourth elements separately. Use built-in functions like max(), min(), and sum().

Create a recursive function to print the Fibonacci series up to n terms.

  1. Define a recursive function fibonacci(n).
  2. Use if-else for recursion base condition. Write a Python program to input a list of numbers from the user and use map() with a lambda function to create a new list containing the squares of the numbers.
  3. Use map() and lambda.
  4. Print the original and squared lists. Create a list of numbers. Use the filter() function and a lambda function to extract only the even numbers into a new list.
  5. Use filter() and lambda.
  6. Print both the original and filtered lists. Ask the user for a list of numbers. Use the reduce() function along with a lambda function to compute the sum of all numbers.
  7. Import reduce from functools.
  8. Use lambda inside reduce(). Write a program to find the maximum number in a list using reduce() and a lambda function (without using built-in max()).
  9. Use reduce() and lambda.
  10. Print the maximum number found. Write a Python class Book with attributes title, author, and price.
  11. Create a constructor to initialize these values.
  12. Write a method display_details() to display book information. Create at least two book objects and display their details. Write a class Rectangle with attributes length and breadth.
  13. Write a constructor to initialize dimensions.
  14. Write methods to calculate and return the area and perimeter of the rectangle. Create an object and display area and perimeter.

Create a class BankAccount with attributes account_holder, account_number, and balance.

  1. Use a constructor to initialize them.
  2. Write methods deposit(amount) and withdraw(amount) to update the balance.
  3. Also add a method display_balance() to show current balance. Create one object and perform deposit and withdrawal operations. Create a class Employee with attributes name, employee_id, and salary.
  4. Write a constructor to initialize these.
  5. Add a method show_details() to display employee details.
  6. Add a method increment_salary() to increase the salary by a given percentage. Create at least two employee objects and apply salary increment. Create a base class Vehicle with attributes brand and year. Create derived classes Car and Bike which add specific attributes like model for Car and type for Bike. Write methods to display all details. Use constructors and method overriding. Create a base class Shape with a method area(). Create derived classes Rectangle and Circle that override the area() method to calculate area appropriately. Use method overriding (polymorphism). Create a class Employee with attributes like name and salary. Create two subclasses Manager and Developer that inherit from Employee and have their own extra method show_role() that displays their roles. Demonstrate polymorphism by calling the same method (show_role()) from different objects.

Create a basic login form GUI with:

  1. Username and password entry fields.
  2. A "Login" button that shows a message like “Login Successful” on clicking. Use Label , Entry , and Button widgets. Display feedback using messagebox. Create a Python program to:
  3. Connect to an SQLite database.
  4. Create a students table (if it doesn’t exist).
  5. Insert at least 3 student records (name, age, grade).
  6. Fetch and display all student records. Use DDL (CREATE TABLE) and DML (INSERT, SELECT) commands. Use sqlite3 module in Python. Write a Python program that:
  7. Creates an employees table with fields: id, name, salary.
  8. Inserts at least two employee records.
  9. Updates the salary of one employee.
  10. Deletes one employee record by name.
  11. Displays all remaining records. Use DDL (CREATE TABLE) and DML (INSERT, UPDATE, DELETE, SELECT). Use sqlite3 with commit and close statements properly. Write a program that:
  12. Creates a Pandas DataFrame with names and marks of 5 students.
  13. Uses NumPy to calculate the average, maximum, and minimum marks.
  14. Uses Matplotlib to display a bar chart of student names vs. marks. Use pandas.DataFrame, numpy.mean(), and matplotlib.pyplot.bar().

Create a program that:

  1. Loads monthly sales data into a Pandas DataFrame (e.g., 6 months).
  2. Calculates the total and average sales using NumPy.
  3. Plots a line graph of month vs. sales using Matplotlib. Use pandas, numpy, and matplotlib.pyplot.plot().