Python Practial File _2023-24 Old.docx
Python Practial File _2023-24 Old.docx
NO E
Unit 3 : Advanced Python Programs
15.
1. Write a program to create a Simple Calculator for any two input numbers
2. Write a program to check whether the given character is an uppercase letter or
lowercase letter or a digit or a special character.
OUTPUT - 1
OUTPUT - 2
3. Write a program to input a sales amount and calculate the discount as :
OUTPUT - 1
OUTPUT - 2
4. Write a program to input a number and check the following, if the number is
OUTPUT – 1
OUTPUT - 2
5 Write a program to print square of all numbers present in a list [8,2,7,11,20].
OUTPUT
6 Write a short program to print the following series up to N terms
c) 1 4 7 10 …N term
d) N N-2 N-4 N-6 …
a) ..
OUTPUT
b)
OUTPUT
7 write a program to input a positive number and prints its factorial. The factorial of a
number is as :
For positive number n is: n*(n-1)*(n-2)*….*1
For negative number : no factorial for negative number
For zero is :1
OUTPUT - 1
OUTPUT – 2
OUTPUT - 3
9 Write a program to calculate and print the sum of even and odd integers of the
first N natural numbers. ( Use while loop only)
OUTPUT – 1
OUTPUT – 2
OUTPUT
1. Write a program to create array using NumPy.
a) Create one-dimensional array
OUTPUT
b) Creating 2D
array OR
Write a program to develop a matrix of 3x3 with values from
5 to 50 with increment of 5
OUTPUT
2. Creating an array with 3 random values
OUTPUT
OUTPUT
4. Write a program to represent the data on the ratings of mobile games on
bar chart. The sample data is given as:
OUTPUT
5. Observe the given data for monthly sales of one of the salesmen
for given months. Plot them on
the LINE CHART
Month January February March April
Sales 2500 1700 3500 1200
OUTPUT
Computer vision is a field of AI that focuses on enabling computers to identify
and understand objects, Intercept and extract information from images and videos,
in a manner similar to human vision
Few examples:
● Facial recognition.
● Self-driving cars.
● Robotic automation.
● Medical anomaly detection.
● Agricultural monitoring.
● Google lens
cv2 is a powerful library for working with images in Python. Few function of cv2 are:
cv2.imread()
This function loads an image from the specified file
syntax : cv2.imread(location of file, file name)
cv2.imshow()
this function is used to display an image in a window .The window automatically fits the image size.
Syntax: cv2.imshow(window_name, image)
cv2.waitKey()
This function display a window for several milliseconds.
cv2.waitKey(0).
If 0 is passed as an argument, it wait/display a window forever until any key is
pressed.
OpenCV images are stored as three-dimensional Numpy arrays to carry out complex
calculations with high speed.
OUTPUT
OUTPUT
10. Save the Image (Hint : Use cv2.imwrite() function)
OUTPUT :
ACTIVITY
Python Library
● A library is a collection of books or is a room or place where many books are stored to be
used later. Similarly, in the programming world, a library is a collection of precompiled
codes that can be used later on in a program for some specific well-defined operations.
● A Python library is a collection of related modules. It contains bundles of code that can
be used repeatedly in different programs. It makes Python Programming simpler and
convenient for the programmer. As we don’t need to write the same code again and
again for different programs.
● Python libraries play a very vital role in fields of Machine Learning, Data Science, Data
Visualization, etc.
● Numpy, Pandas, TensorFlow are example of python library.
● Numeric, Numarray are package of Numpy library.
PYTHON MODULE
● A Python module is single python file, containing Python definitions and statements.
● A module can also include runnable code. Grouping related code into a module
makes the code easier to understand and use.
PYTHON PACKAGE
1. NumPy –
2. OpenCV :
● It is mainly used for image processing and support various functions related
to image manipulations.
3. Matplotlib :
● It stands for Natural Language Tool Kit supports features related to textual data.
● It is used for Natural Language Processing.
5. Pandas :
After installation of packages, you need to import them into the program.
1. import numpy
2. import matplotlib.pyplot as chart
3. import opencv as cv
4. from numpy import array
PROGRAMS OF 2022 – 23
● FOR PRACTICE ONLY
● DON’T WRITE IN PRACTICAL FILE
else:
print("All are same")
4. An electric power distribution company charges its
domestic consumers as follows:
CONSUMPTION RATE OF CHARGE
UNITS
0-100 Rs. 1 per unit
101-300 Rs. 100 plus Rs. 1.25 per unit in excess of 100
301-500 Rs. 350 plus Rs. 1.50 per unit in excess of 300
500 and above Rs. 650 plus Rs. 1.75 per unit in excess of 500
Write a program that read the customer number & power consumed and prints the
amount to be paid by the customer. Note that output should be well formatted..
OUTPUT :
5. Program to print sum of natural numbers between 1 to N.
OUTPUT
OUTPUT
7. Write a program to input a number and print its reversed number.
OUTPUT
OUTPUT
9. Write a program to calculate and print the sum of even and odd integers
of the first N natural numbers. ( Use while loop)
OUTPUT
Scatter plot
Bar chart
Histogram
Box plots
Lll
sdsd
OUTPUT