EXERCICES ON Python PROGRAMMING LANGUAGE
EXERCICES ON Python PROGRAMMING LANGUAGE
1. Basics of Python
2. Conditional Statements
Write a program to check whether a number entered by the user is positive, negative,
or zero using an if-elif-else statement.
Create a program that assigns a grade based on the user’s score using nested if
statements. (e.g., A for scores above 90, B for 80-89, etc.)
Write a program to determine whether a given year is a leap year.
3. Loops
Write a program to print the multiplication table of a number entered by the user, up to
12 rows.
Create a program to calculate the factorial of a number using a for loop.
Write a program to sum all numbers in a list using a while loop.
4. Functions
Write a function is_prime(n) that checks whether a number is prime. Test it with
several inputs.
Create a function reverse_string(s) that takes a string as input and returns it
reversed.
Write a recursive function to calculate the Fibonacci sequence up to a given number.
Write a program to find the largest and smallest numbers in a list of integers.
Create a program that demonstrates slicing operations on a list. (e.g., reverse the list,
extract even-indexed elements)
Write a program to merge two lists and remove duplicates.
Write a program to create a text file, write a series of numbers to it, then read the
numbers and display them.
Create a program that counts the number of lines, words, and characters in a text file.
Write a program to copy the contents of one file to another.
8. Object-Oriented Programming
Define a class called Rectangle with attributes length and width. Add methods to
calculate and print the area and perimeter.
Create a class BankAccount with methods for deposit, withdrawal, and checking
balance. Use it to simulate basic banking operations.
Write a program that demonstrates inheritance by creating a Base class and a Derived
class with overridden methods.
9. Exception Handling
Additional Challenges
1. Write a program that simulates a basic "To-Do List" application where users can add,
mark as complete, and delete tasks.
2. Create a text-based Tic-Tac-Toe game where two players can play against each other.
3. Build a small inventory management system using classes and dictionaries to track
items, their quantities, and prices.
4. Write a program that implements a simple web scraper using BeautifulSoup to
extract data from a website.
Bonus Challenge
Build a Python program that creates a graphical user interface (GUI) for a basic
calculator using the tkinter library.