0% found this document useful (0 votes)
5 views34 pages

Python Notes - Class 11th Class 12th - Practical

The document provides a comprehensive guide to learning Python over a week, covering topics such as file extensions, data types, operators, conditional statements, loops, functions, lists, tuples, dictionaries, sets, and object-oriented programming. Each day includes practice questions to reinforce learning and help users apply their knowledge. Additional resources and notes are provided for further reference.

Uploaded by

manahilaman012
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views34 pages

Python Notes - Class 11th Class 12th - Practical

The document provides a comprehensive guide to learning Python over a week, covering topics such as file extensions, data types, operators, conditional statements, loops, functions, lists, tuples, dictionaries, sets, and object-oriented programming. Each day includes practice questions to reinforce learning and help users apply their knowledge. Additional resources and notes are provided for further reference.

Uploaded by

manahilaman012
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

 Notes: [Link]

org/python/python-basics/
 Python Coding IDE: [Link]
utm_medium=playground&utm_source=python_playground-save-button

Day 1
Python File Extension: .py
Input: Take value from the user
Output: Display value on the screen

Single line comments: #


Multi-line comments: “”” “””

Data types define the kind of data a variable can hold and determine the operations that can be
performed on it
Examples of Datatypes

To specifically take input in a certain datatype:

Some Common Shortcuts:


Function Shortcut
Select All Ctrl + A
Copy Ctrl + C
Paste Ctrl + V
Undo Ctrl + Z

Practice Questions:

1. Write a Python program that takes your name as input and prints a welcome message
with your name.
2. Write a Python program to take your age as input, store it in a variable, and print it.
3. Write a Python program that uses a comment, takes your favorite color as input, and
prints:
My favorite color is [color]
4. Write a Python program to store the following in variables and print them:
o your name
o your age
o your height
o whether you are a student or not
5. Write a Python program that asks the user for their city and country and then prints:
[city] is in [country]
6. Write a Python program that includes at least two comments, takes the user’s name and
university, and prints both.
7. Write a Python program to identify and use these data types in variables:
o str
o int
o float
o bool
8. Write a Python program that asks for your favorite subject and semester and then prints
them in one sentence.
9. Write a Python program that asks the user:
Are you learning Python?
Store the answer in a variable and print it.
10. Write a Python program to make a simple student profile using:

 input
 output
 comments
 at least 3 different data types
Day 2
Operators
 Arithmetic Operations
(Used for performing
operations on variables
\numbers)

 Comparison Operators
(Used to compare number)

 Logical Operators
(Used for logical operations of
AND, OR, NOT)

 Bitwise Operators
(Used for working on bits)W

 Assignment Operators
(assign values to variable)

Conditional Statements
 If Else
(if condition is satisfied, then run ‘if’.
if condition is not satisfied, then run ‘else’)
Important Note

Practice Questions:
1. Write a Python program that takes two numbers as input and prints their sum,
difference, product, and division.
2. Write a Python program to check whether a given number is even or odd.
3. Write a Python program that takes a user’s age as input and checks whether the user is
eligible to vote or not.
4. Write a Python program to compare two numbers and print which one is greater, or if
they are equal.
5. Write a Python program that takes a number as input and checks whether it is positive,
negative, or zero.
6. Write a Python program to take marks as input and print “Pass” if marks are 40 or
above, otherwise print “Fail”.
7. Write a Python program that asks the user for two numbers and checks whether the first
number is greater than the second.
8. Write a Python program that takes a number as input and checks whether it is divisible
by 5 or not.
9. Write a Python program to calculate the remainder when one number is divided by
another.
10. Write a Python program that takes a user’s salary as input and checks whether it is
greater than 50,000 or not.
11. Write a Python program to check whether a given number lies between 1 and 100.
12. Write a Python program that takes a number as input and checks whether it is a multiple
of 3.
13. Write a Python program to take the user’s temperature as input and print:

 “Hot” if temperature is above 30


 “Cold” otherwise

14. Write a Python program that asks for a user’s password and checks whether it matches a
given password.
15. Write a Python program to check whether a person is a child, teenager, or adult based
on age.
16. Write a Python program that takes three numbers as input and prints the largest
number.
17. Write a Python program to check whether a number is divisible by both 2 and 3.
18. Write a Python program that takes the user’s shopping amount as input and gives a
discount if the amount is greater than 5000.
19. Write a Python program to check whether a student’s attendance percentage is enough
to sit in the exam.
20. Write a Python program that asks the user for a number and checks whether it is less
than, greater than, or equal to 50.
Day 3
Loops
 For
(runs a block of code once
for each item in the sequence)

 While
(continues to execute as
long as a condition is true)

Dry Run
(used to see the internal working of a
program or piece of code)

Functions
(a block of reusable code
that performs a specific task)

Important Note
 Indentations (spaces) matter a lot
 If there are spaces in function name, then we use _ instead of space
 if we divide any number by 2, and we get remiander 0, it is even
 and if the remainder is 1, then the number is odd
Practice Questions:
1. Write a Python program using a for loop to print numbers from 1 to 10.
2. Write a Python program using a for loop to print all even numbers from 1 to 20.
3. Write a Python program using a for loop to print your name 5 times.
4. Write a Python program using a for loop to find the sum of numbers from 1 to 10.
5. Write a Python program using a for loop to print the multiplication table of 5.
6. Write a Python program using a for loop to count how many numbers are between 1 and
50.
7. Write a Python program using a for loop to print all the odd numbers from 1 to 15.
8. Write a Python program using a for loop to print the square of numbers from 1 to 10.
9. Write a Python program using a for loop to print all characters of a given string one by
one.
10. Write a Python program using a for loop to calculate the factorial of a number.
11. Write a Python function named greet() that prints “Hello, Welcome to Python”.
12. Write a Python function named student() that prints your name and roll number.
13. Write a Python function named add() that takes two numbers and prints their sum.
14. Write a Python function named square() that takes a number and prints its square.
15. Write a Python function named evenOdd() that checks whether a number is even or odd.
16. Write a Python function named table() that prints the table of a given number.
17. Write a Python function named maxNum() that takes two numbers and prints the greater
one.
18. Write a Python function named message() that takes a name as input and prints a
personalized greeting.
19. Write a Python function named countChars() that takes a string and prints the number of
characters in it.
20. Write a Python function named checkPass() that takes marks as input and prints Pass or
Fail.

Dry Run Questions


(Trace the code step by step and write the output / final value of variables)

21. Dry run the following logic:


A loop prints numbers from 1 to 5. What will be the output?
22. Dry run a program that uses a for loop to print all even numbers from 2 to 10.
23. Dry run a loop that adds numbers from 1 to 4 and stores the result in a variable called
sum.
24. Dry run a program where a for loop prints the word “Python” three times.
25. Dry run a function add(2, 3) that prints the sum of two numbers.
26. Dry run a function square(4) that prints the square of the number.
27. Dry run a loop that prints the table of 3 from 1 to 5.
28. Dry run a function that checks whether the number 7 is even or odd.
29. Dry run a loop that prints each letter of the word “HELLO” one by one.
30. Dry run a program where a loop calculates the sum of odd numbers from 1 to 9.
Day 4
Notes: [Link]

List

Common Errors (List)


Adding an element, which increases the size of the initial list

Giving size with the name of the list is not allowed

Removing from a List – By Value

Removing from a List – By Index

Inserting an Item in a List – By Value

Inserting an Item in a List – By Index


Tuple

Get Size Of

Important Notes

Practice Questions:

1. Write a Python program to create a list of 5 fruits and print it.


2. Write a Python program to create a list of 3 numbers and print all elements of the list.
3. Write a Python program to add a new item to an existing list.
4. Write a Python program to remove an item from a list.
5. Write a Python program to modify the second element of a list.
6. Write a Python program to create a list of student names and print the first and last
element.
7. Write a Python program to create a list of colors, then replace one color with another.
8. Write a Python program to add two new numbers to a list.
9. Write a Python program to remove the last element from a list.
10. Write a Python program to create a list and print its length.
11. Write a Python program to create a tuple of 5 numbers and print it.
12. Write a Python program to create a tuple of 3 cities and print each element.
13. Write a Python program to create a tuple and access its first element.
14. Write a Python program to create a tuple and access its last element.
15. Write a Python program to create a tuple of student marks and print all values.
16. Write a Python program to compare a list and tuple containing the same elements.
17. Write a Python program to create a tuple of days of the week and print any 3 days.
18. Write a Python program to count the number of elements in a tuple.
19. Write a Python program to create a tuple and print its data type.
20. Write a Python program to create both a list and a tuple with the same values and
display them.
21. Write a Python program to show size of a list.
22. Write a Python program to show size of a tuple.
23. Write a Python program to compare the memory size of a list and a tuple.
24. Write a Python program to create a list of integers and print its size.
25. Write a Python program to create a tuple of integers and print its size.
26. Write a Python program to check the size of an integer.
27. Write a Python program to check the size of a float.
28. Write a Python program to create two lists of different lengths and compare their memory
size.
29. Write a Python program to create two tuples of different lengths and compare their
memory size.
Day 5

Dictionary

Notes: [Link]

Syntax: key:value

Len() – for length of the collection

Type() – for type of variable

Dict() – acts as a constructor; initializes values of dictionary

Sets

Notes: [Link]
Len() - for length of the collection

Type() – for type of variable

Set() – acts as constructor; initializes a set

Practice Questions:

1. Create a set containing the numbers 1, 2, 3, 4, 5 and print it.


2. Add the number 6 to the set from question 1.
3. Remove the number 3 from the set.
4. Check if the number 4 exists in the set.
5. Clear all elements from the set.
6. Convert a list [1, 2, 2, 3, 3, 4] into a set to remove duplicates.
7. Iterate over a set and print each element.
8. Create a dictionary with keys 'name', 'age', and 'city' and assign any values to them.
9. Access and print the value of the 'age' key.
10. Add a new key 'country' with a value to the dictionary.
11. Update the value of the 'city' key.
12. Delete the 'age' key from the dictionary.
13. Check if 'name' is a key in the dictionary.
Day 6

Notes: [Link]

 Class is characteristics of an object; user-defined data type


 Object is an instance of a class

To see the value of the variable in the class

To see the address of the object of the class


Example

Del() – deletes an object

Changing values of attributes of a class


Multiple objects of a class

Pass – helps bypassing a class that isn’t to be used or has no code in it yet

Practice Questions:

1. Create a class named Student.


2. Create an object of the Student class. Also, display the address of the object.
3. Create a class named Car and make one object of it.
4. Create a class named Book and make an object called b1. Also, display the address of the
object.
5. Create a class named Laptop and print the object.
6. Create a class named Dog and make two objects of it. Also, display the address of the
objects.
7. Create a class named Mobile and create three different objects.
8. Create a class named Pen and make two objects named p1 and p2. Also, display the
address of the objects.
9. Create a class named Fan and create multiple objects of it.
10. Create a class named Chair and make 4 objects.
11. Create a class Student and assign name to one object.
12. Create a class Car and assign color to one object.
13. Create a class Book and assign title to one object. Also, display the address of the object.
14. Create a class Phone and assign brand to two different objects.
15. Create a class Animal and assign type to one object.
16. Create an object of a class and then delete it using del.
17. Create two objects of a class and delete one of them.
18. Create an object s1 of class Student and delete it.
19. Create an object c1 of class Car, print it, then delete it.
20. Create three objects and delete the second one.
21. Create an empty class using pass.
22. Make a class Teacher with no code inside it using pass.
23. Create a class School using only the pass keyword.
24. Make an empty class House and create its object.
25. Create an empty class Bag using pass and make two object
26. Create a class Bike and make two objects.
27. Create a class Person using pass.
28. Create a class Fruit, make one object, and delete it.
29. Create a class Bottle and make three objects.
30. Create an empty class Table and create one object.
31. Create any class and its 4 objects. Display the address of all objects
32. Create a class called “animals” and add any 3 characteristics of animals. Create 2 objects
and display the address and values of both the objects.
Day 7

Notes: [Link]

Class includes

1. Data members
2. Member function (also called methods)

Example:
Class – Animal
Data members – name, color, age, species, weight, height
Member functions – walk, sound, sleep, eat

__init__ ; used for constructor; assigns values to the data members of the class

Pillars of OOP

Inheritance: allows a class (child class) to acquire properties and methods of another class
(parent class). It supports hierarchical classification and promotes code reuse.
Polymorphism: means "same operation, different behavior." It allows functions or methods with
the same name to work differently depending on the type of object they are acting upon
Two types of polymorphism

Compile Time Polymorphism Run Time Polymorphism


Decided during compilation Decided during program
execution
Also called Static Polymorphism Also called Dynamic
Polymorphism
Achieved by Function Overloading and Operator Achieved by Function Overriding
Overloading
Faster Slightly slower
Inheritance is not necessary Inheritance is required
The function call is decided by the compiler The function call is decided at
runtime

Encapsulation: is the bundling of data (attributes) and methods (functions) within a class,
restricting access to some components to control interactions.

Abstraction: hides unnecessary data


Day 8

Important points:

 It is not compulsory to have data members, but it is compulsory to have member


functions
 The first member function is always a constructor
 Common between all: goes to data members
 Not common between all: goes to constructor
 ‘Display details’ function has no parameters
 ‘Self’ refers to objects of the class
 Parameters or arguments: Attributes or variable which a function uses

Q1.

Q2.
Practice Questions:


Day 9
File Handling
Notes: [Link]
Text File Extension: .txt
1. Opening a File

2. Closing a File

3. Checking File Properties

4. Reading a File

5. Writing in a File

6. Append
 Takes the cursor to the end of the file
| Output:
7. Handling Exceptions When Closing a File

Using ‘With’ and ‘As’ Statement


 Used for an instruction
 Combined with ‘as’ keyword
 ‘as’ assigns variable to instruction and ‘with’ has the instruction next to it.

Practice Questions:
1. Write a Python program to create a file and write your name into it.
2. Write a program to read the contents of a file and display it on the screen.
3. Write a program to count the number of characters in a file.
4. Write a program to count the number of words in a file.
5. Write a program to count the number of lines in a file.
6. Write a Python program to create a file and write your name into it.
7. Write a program to read the contents of a file and display it on the screen.
8. Write a program to count the number of characters in a file.
9. Write a program to count the number of words in a file.
10. Write a program to count the number of lines in a file.
11. Write a Python program to create a file and write your name into it.
12. Write a program to read the contents of a file and display it on the screen.
13. Write a program to count the number of characters in a file.
14. Write a program to count the number of words in a file.
15. Write a program to count the number of lines in a file.
16. Write a Python program to create a file and write your name into it.
17. Write a program to read the contents of a file and display it on the screen.
18. Write a program to count the number of characters in a file.
19. Write a program to count the number of words in a file.
20. Write a program to count the number of lines in a file.
Day 10
Library: Tkinter
Notes: [Link]
(Done till 10. Scale)
Practice Questions:
1. Create a simple window with a title and fixed size.
2. Add a Label that displays “Hello, World!”.
3. Add a Button that prints a message in the console when clicked.
4. Create a window with multiple labels showing your name, course, and university.
5. Add an Entry widget and display the entered text in the console on button click.
6. Create the same UI using pack() layout.
7. Create a window with:
 Title “My First App”
 Size 400x300
 Display a Label that says “Welcome to Tkinter”.
 Add a Button that prints “Button Clicked” in the console.
Create a window with 2 labels showing:
 Your name
 Your course
8. Add an Entry box and a button. When clicked, print the entered text.
9. Take input from user and display it in a Label.
10. Create a program that asks user name and shows:
👉 “Hello, [Name]”
11. Create a button that changes label text when clicked.
12. Add two buttons:
 One shows “ON”
 One shows “OFF”
13. Create a button that closes the window.
14. Create a button that changes window background color.
15. Display current text from Entry when pressing a button.
16. Count how many times a button is clicked and display the count.
17. Create a simple addition app (2 inputs + result label).
18. Make a greeting app that displays a welcome message.
19. Create a window with different colored labels.
20. Show a message when user enters empty input.
21. Create a basic feedback form (name + message + submit).
Day 11
Library: Turtle
Notes:
 [Link]
 [Link]
IDE: [Link]

Square

Star
Pentagon

Spiral Square

Practice Questions:
1. Draw a straight line using turtle.
2. Draw a rectangle with different length and width.
3. Draw a triangle.
4. Draw a circle.
5. Draw a hexagon (6 sides).
6. Draw a star shape.
7. Draw multiple squares in a row.
8. Draw a pattern of circles (like 5 circles in a line).
9. Draw a square and fill it with a color.
10. Draw 5 squares, each with a different color.
11. Draw a rainbow using semicircles.
12. Create a colorful spiral pattern.
13. Draw a flower using repeated circles.
14. Move the turtle to different positions and draw shapes at each position.
15. Draw a house (square + triangle roof).
16. Draw a simple car using basic shapes.
17. Draw the initials of your name using turtle.
18. Draw a flag of any country.
19. Use a loop to draw a square.
20. Use a loop to draw 10 circles.
21. Draw a spiral using a loop.
22. Create a pattern using nested loops.
23. Draw a clock with numbers (basic version).
Day 12
Library: Pandas, Matplotlib
Notes: [Link]
cs=0&hl=en-US&biw=1280&bih=551.3333740234375
IDE: [Link]
Step 1: import the pandas library.

Step 2: store the csv in the ‘data’. If gives error go in the folder icon at the second last on the left
side panel, and upload the csv file from there. Then run this line of code again

Step 3: printing some first rows to verify if the database is working or not

Step 4: installing matplotlib library to make charts and graphs from the database
Different types of graphs
 Scatter Plot
 Two different numeric values
 X axis: independent variable
 Y axis: dependent variable
 Used to identify relationships, correlations, and patterns

 Line Chart
 connects individual data points with straight lines to show trends, patterns, and
fluctuations over a continuous interval, typically time
 Best for displaying data changes over time, such as stock prices, temperature, or
company revenue
 X axis: continuous variables
 Y aix: quantiative variables
 Bar Chart
 Compares catagorical data
 One axis displays the categories, while the other shows the numerical scale or
frequency.
 Compares multiple quantities within each category.

 Histogram
 No gaps between bars
 Summarizes large datasets to visualize trends and patterns
 The X-axis represents numerical ranges (bins), while the Y-axis represents the
frequency or count.
Practice Questions:
1. You are given monthly sales data for a store. Plot a line chart showing sales trend over 12
months.
2. Plot two line graphs on the same chart to compare sales of two products over a year.
3. Given daily temperatures for a week, plot a line graph and highlight the maximum
temperature point.
4. Create a bar chart showing number of students enrolled in different courses (CS, IT, SE,
AI).
5. Given marks of 5 students in a subject, plot a bar chart and color the highest mark
differently.
6. Create a grouped bar chart comparing boys vs girls marks in 3 subjects.
7. Generate random data of 100 students' marks and plot a histogram.
8. Change the number of bins and observe how the distribution changes.
9. Plot a histogram and add a title + axis labels + grid.
10. Given data of hours studied vs marks obtained, create a scatter plot.
11. Modify the scatter plot by changing color and marker style.
12. Add a trend line (best-fit line) to the scatter plot.
13. Create a dataset of weekly study hours and plot it using a line graph.
14. Given monthly expenses, plot both a bar chart and a pie chart for comparison.
15. Create a dataset of students' marks in 3 subjects and visualize it using grouped bar charts.
16. Plot random heights of people and visualize distribution using histogram.
17. Combine multiple plots (line + scatter) to analyze the same dataset.

The
End

You might also like