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

Python Practice Workbook

The document is a Python practice workbook designed for different skill levels, including beginner, intermediate, and advanced exercises. It covers topics such as basic syntax, data types, control flow, functions, file handling, OOP, error handling, data structures, algorithms, web scraping, and advanced libraries. Additionally, it provides project ideas and encourages users to refer to official documentation and optimize their code.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Python Practice Workbook

The document is a Python practice workbook designed for different skill levels, including beginner, intermediate, and advanced exercises. It covers topics such as basic syntax, data types, control flow, functions, file handling, OOP, error handling, data structures, algorithms, web scraping, and advanced libraries. Additionally, it provides project ideas and encourages users to refer to official documentation and optimize their code.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Python Practice Workbook

Beginner Level

1. Basic Syntax and Variables

 Write a program to print "Hello, World!".

 Create variables for your name, age, and favorite


color. Print them in a sentence.

 Convert a temperature from Celsius to Fahrenheit.

Formula: F = (C * 9/5) + 32
2. Data Types and Operations

 Write a program to calculate the area of a rectangle.

Input: Length and width.

Output: Area.

 Use string methods to manipulate a given string


(e.g., reverse, uppercase).

 Perform arithmetic operations on two numbers


entered by the user.
3. Control Flow (If-Else, Loops)

 Write a program to check if a number is even or odd.

 Create a loop that prints numbers from 1 to 10.

 Write a program to find the largest of three numbers


entered by the user.

Intermediate Level

4. Functions and Modules

 Write a function to calculate the factorial of a


number.

 Create a module to perform basic mathematical


operations (add, subtract, multiply, divide).
 Use Python’s math module to calculate the square
root of a number.

5. File Handling

 Write a program to read a text file and count the


number of words.

 Create a program to write a list of names to a file.

 Append data to an existing file and then read the


updated content.
6. Object-Oriented Programming (OOP)

 Define a Person class with attributes like name and


age. Create a method to display details.

 Extend the Person class to create a Student class


with additional attributes.

 Create a class for a bank account with methods to


deposit, withdraw, and display the balance.

7. Error Handling

 Write a program that handles division by zero with a


custom error message.

 Implement a try-except block to manage invalid user


input.
 Create custom exceptions for invalid operations in a
banking application.

Advanced Level

8. Data Structures

 Implement a stack and a queue using Python lists.

 Write a program to perform binary search on a


sorted list.

 Create a program to merge and sort two lists.

9. Algorithms

 Write a program to solve the Fibonacci sequence


using recursion.
 Create a program to sort a list of numbers using
bubble sort.

 Implement a program to check if a string is a


palindrome.

10. Web Scraping and APIs

 Use the requests library to fetch data from a public


API and display it.

 Write a web scraper using BeautifulSoup to extract


headlines from a news website.

 Scrape weather data for your city and display it in a


user-friendly format.

11. Advanced Libraries


 Use NumPy to perform matrix operations (e.g.,
addition, multiplication).

 Create a basic data visualization with matplotlib


(e.g., a bar chart of monthly expenses).

 Analyze a dataset using pandas to calculate statistics


like mean, median, and mode.

12. Project Ideas

 Build a to-do list application.

 Create a simple calculator with a GUI using Tkinter.


 Develop a command-line-based budget tracker.

 Create a game (e.g., Hangman or Tic-Tac-Toe).

 Build a program to manage student records with


CRUD operations.

Instructions

Complete each exercise in a new Python file.

Refer to Python’s official documentation for guidance:


Python Docs.

Test your solutions with various inputs to ensure


correctness.

As you progress, aim to refactor and optimize your code.

You might also like