Introduction:
This lesson contains all practice exercises from the course. Attempt these exercises to reinforce your learning and prepare effectively for the final test. The exercises cover Python Basics, Control Flow, Functions, Data Structures, File Handling, OOP, and Advanced Topics.
1. Python Basics Exercises
-
Write a program to swap two numbers without using a third variable.
-
Print your name and age using Python input and output.
-
Write a program to calculate the area of a rectangle.
-
Convert temperature from Celsius to Fahrenheit.
-
Check whether a number is even or odd.
2. Control Flow Exercises
-
Write a program to print all prime numbers between 1 and 100.
-
Find the largest of three numbers using if-else.
-
Write a program to print multiplication table of a given number.
-
Calculate the sum of all numbers from 1 to N using a loop.
-
Write a program to check whether a number is a palindrome.
3. Functions & Modules Exercises
-
Write a function to find factorial of a number.
-
Create a function that checks if a string is a palindrome.
-
Write a function to calculate the area of a circle (radius as input).
-
Import Python’s math module and calculate the square root of a number.
-
Create a function that takes a list and returns the largest element.
4. Data Structures Exercises
-
Create a list of numbers and print only the even numbers.
-
Remove duplicates from a list.
-
Create a tuple of 5 elements and print the 3rd element.
-
Create a set of 5 numbers and add 2 new numbers.
-
Create a dictionary of 5 students with marks and print each student’s marks.
-
Take a string and count the number of vowels.
-
Format a string using
.format()to include your name and age.
5. File Handling & Exception Exercises
-
Write a program to read a file named
data.txtand print its content. -
Write a program to write a list of names to a file.
-
Use try-except to handle division by zero.
-
Raise a custom exception if a number is negative.
6. Object-Oriented Programming Exercises
-
Create a class Student with attributes
name,ageand a methoddisplay(). -
Create a class BankAccount with deposit and withdraw methods.
-
Implement inheritance: Create a class
Teacherinheriting fromPerson. -
Implement encapsulation: Create a class with a private attribute and getter/setter methods.
7. Advanced Topics Exercises
-
Using Python’s random module, generate a random number between 1 and 100.
-
Using Python’s datetime module, print the current date and time.
-
Using BeautifulSoup, extract all links (
<a>tags) from a sample HTML page. -
Using SQLite, create a table
employeeswith columnsid,name,salary. -
Write a Python program to connect to a database and insert records.
Conclusion:
Attempt all these exercises to strengthen your Python skills. After practicing, you will be ready to take the Final Test – Python Programming Assessment and earn your certificate upon scoring 70% or above.
