001 Exercises in python fundamentals
001 Exercises in python fundamentals
1|E x e r c i s e s i n P y t h o n F u n d a m e n t a l s
3. FUNCTIONS AND MODULAR PROGRAMMING
EXERCISE 1: AREA CALCULATOR
Write a function that calculates and returns the area of a circle based on its radius. Prompt the user to input the
radius and then use the function to calculate and display the area.
EXERCISE 2: GRADE CALCULATOR
Write a function that takes a student's score as input and returns their corresponding letter grade based on the
following scale:
• 90-100: A
• 80-89: B
• 70-79: C
• 60-69: D
• Below 60: F
2|E x e r c i s e s i n P y t h o n F u n d a m e n t a l s
EXERCISE 5: SHOPPING LIST
Design a program that simulates a shopping list. Use a dictionary to store items as keys and their corresponding
quantities as values. Implement the following:
a) Add items and quantities to the shopping list.
b) Remove items from the list if they are purchased.
c) Print the final shopping list.
5. FILE HANDLING
EXERCISE 1: FILE READING AND PRINTING
Write a program that reads a text file named "data.txt" and prints its contents to the console.
EXERCISE 2: LINE COUNTER
Create a program that reads a text file (use some kind of placeholder text) and counts the number of lines in it.
Display the total number of lines at the end.
EXERCISE 3: FILE COPY
Write a program that reads the contents of one text file (use some kind of placeholder text) named "source.txt"
and writes them to another text file named "destination.txt".
EXERCISE 4: WORD FREQUENCY COUNTER
Design a program that reads a text file (use any paragraph from any media source/ news article) and counts the
frequency of each word. Store the word frequencies in a dictionary and print the results.
EXERCISE 5: CSV DATA ANALYSIS
Assume you have a CSV file "data.csv" with rows of student names and their corresponding scores. Write a
program that reads the CSV file, calculates the average score, and prints the names of students who scored above
the average.
3|E x e r c i s e s i n P y t h o n F u n d a m e n t a l s
7. INTRODUCTION TO CLASSES AND OBJECTS
EXERCISE 1: SIMPLE CLASS CREATION
Create a class called `Person` with attributes `name` and `age`. Write a constructor to initialize these attributes,
and a method to print the person's details.
EXERCISE 2: BANK ACCOUNT
Design a class `BankAccount` that represents a basic bank account. Include attributes for the account holder's
name, account number, and balance. Implement methods to deposit and withdraw funds, and display the current
balance.
EXERCISE 3: CIRCLE AREA CALCULATOR
Define a class `Circle` with a constructor that takes the radius as a parameter. Include a method to calculate and
return the area of the circle. Create instances of the class to calculate areas of circles with different radii.
EXERCISE 4: BOOK INFORMATION
Create a class `Book` that represents a book. Include attributes for the book's title, author, and publication year.
Implement methods to display the book's details.
4|E x e r c i s e s i n P y t h o n F u n d a m e n t a l s