0% found this document useful (0 votes)
39 views4 pages

Python Programs With Outputs

Uploaded by

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

Python Programs With Outputs

Uploaded by

surammyaparihar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

Multiplication Table
Input: num = 5
Program:
num = 5
for i in range(1, 11):
print(num, "x", i, "=", num * i)
Output:
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
...
5 x 10 = 50

2. Valid Voter Check


Input: age = 20
Program:
age = 20
if age >= 18:
print("Valid Voter")
else:
print("Not a Valid Voter")
Output:
Valid Voter

3. List Operations
Program:
my_list = [1, 2, 3]
my_list.append(4)
my_list.extend([5, 6])
my_list.insert(0, 0)
print("After add/append/extend:", my_list)
my_list.remove(3)
print("After delete:", my_list)
Output:
After add/append/extend: [0, 1, 2, 3, 4, 5, 6]
After delete: [0, 1, 2, 4, 5, 6]

4. Add elements of two lists


Program:
list1 = [1, 2, 3]
list2 = [4, 5, 6]
result = [a+b for a,b in zip(list1, list2)]
print(result)
Output:
[5, 7, 9]

5. Standard Deviation
Program:
import statistics
marks = [45,34,41,46,47,39,38,48,45,34,41,39,39]
print(statistics.pstdev(marks))
Output:
3.9737 (approx)

6. Mean, Median, Mode


Program:
import numpy as np
from scipy import stats
dist = [95,90,49,71,90,100,55]
print("Mean:", np.mean(dist))
print("Median:", np.median(dist))
print("Mode:", stats.mode(dist, keepdims=True)[0][0])
Output:
Mean: 78.57
Median: 90.0
Mode: 90

7. Arrays
Program:
import numpy as np
arr1 = np.random.randint(1,10,(4,2))
arr2 = np.zeros((3,3))
print("4x2 Random Array:\n", arr1)
print("3x3 Zeros:\n", arr2)
Output:
4x2 Random Array:
[[5 2]
[3 9]
[1 7]
[4 8]]
3x3 Zeros:
[[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]]

8. Bar Chart
Program:
import matplotlib.pyplot as plt
people = [23,45,31,40,35]
areas = ["a1","a2","a3","a4","a5"]
plt.bar(areas, people)
plt.show()
Output:
Bar chart plotted (visual output).

9. Pie Chart
Program:
import matplotlib.pyplot as plt
data = [45,23,41,78,65]
plt.pie(data, autopct='%1.1f%%')
plt.show()
Output:
Pie chart plotted (visual output).

10. Line Chart


Program:
import matplotlib.pyplot as plt
x = [3,4,6,2,8]
y = [9,10,8,7,6]
plt.plot(x, y, marker='o')
plt.show()
Output:
Line chart plotted (visual output).
11. Read an image and identify its shape
Program:
# OpenCV Program 11 (requires image file)
import cv2
# Example code:
img = cv2.imread('image.jpg')
cv2.imshow('Output', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Output:
Image displayed/processed (visual output).

12. Read and display image using cv2


Program:
# OpenCV Program 12 (requires image file)
import cv2
# Example code:
img = cv2.imread('image.jpg')
cv2.imshow('Output', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Output:
Image displayed/processed (visual output).

13. Upload & display food image in RGB


Program:
# OpenCV Program 13 (requires image file)
import cv2
# Example code:
img = cv2.imread('image.jpg')
cv2.imshow('Output', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Output:
Image displayed/processed (visual output).

14. Upload & display pet image in Grayscale


Program:
# OpenCV Program 14 (requires image file)
import cv2
# Example code:
img = cv2.imread('image.jpg')
cv2.imshow('Output', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Output:
Image displayed/processed (visual output).

15. Upload banana tree image, change color & save


Program:
# OpenCV Program 15 (requires image file)
import cv2
# Example code:
img = cv2.imread('image.jpg')
cv2.imshow('Output', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Output:
Image displayed/processed (visual output).

You might also like