0% found this document useful (0 votes)
11 views10 pages

Python_Lab_Manual_All_Programs (1)

Uploaded by

faisalshipper
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)
11 views10 pages

Python_Lab_Manual_All_Programs (1)

Uploaded by

faisalshipper
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/ 10

Python Lab Manual - All 25 Programs

1. Program to Demonstrate Number Data Types

num1 = 5

print(num1, 'is of type', type(num1))

num2 = 2.0

print(num2, 'is of type', type(num2))

num3 = 1 + 2j

print(num3, 'is of type', type(num3))

2. Program to Demonstrate Arithmetic Operators

a=7

b=2

print('Sum: ', a + b)

print('Subtraction: ', a - b)

print('Multiplication: ', a * b)

print('Division: ', a / b)

print('Floor Division: ', a // b)

print('Modulo: ', a % b)

print('Power: ', a ** b)
3. Program to Demonstrate Assignment Operators

a = 10

b=5

a += b

print(a)

a *= 2

print(a)

4. Program to Demonstrate Comparison Operators

a=5

b=2

print('a == b =', a == b)

print('a != b =', a != b)

print('a > b =', a > b)

print('a < b =', a < b)

print('a >= b =', a >= b)

print('a <= b =', a <= b)

5. Program to Demonstrate Logical Operators

print(True and False)


print(True or False)

print(not True)

6. Program to Demonstrate Identity Operators

x1 = 5

y1 = 5

x2 = [1, 2, 3]

y2 = [1, 2, 3]

print(x1 is y1)

print(x2 is not y2)

7. Program to Demonstrate If-Else Statements

a = 33

b = 200

if b > a:

print("b is greater than a")

elif a == b:

print("a and b are equal")

else:

print("a is greater than b")


8. Program to Demonstrate Python Iterators

mytuple = ("apple", "banana", "cherry")

myit = iter(mytuple)

print(next(myit))

print(next(myit))

print(next(myit))

9. Program to Demonstrate Python Modules

import math

print(math.sqrt(16))

print(math.pi)

10. Program to Demonstrate Strings in Python

a = "Hello, World!"

print(a[1]) # Access character

print(len(a)) # Length of string

11. Program to Demonstrate Tuples

mytuple = ("apple", "banana", "cherry")


print(mytuple)

print(mytuple[1])

12. Program to Create, Append, and Remove Lists

mylist = ['apple', 'banana', 'cherry']

mylist.append('orange')

print(mylist)

mylist.remove('banana')

print(mylist)

13. Program to Demonstrate Dictionaries

mydict = {

"brand": "Ford",

"model": "Mustang",

"year": 1964

print(mydict)

print(mydict["brand"])

14. Program to Demonstrate Sets and File Handling

myset = {"apple", "banana", "cherry"}

print(myset)
with open("sample.txt", "w") as f:

f.write("Hello, File Handling!")

15. Program to Demonstrate NumPy Arrays

import numpy as np

arr = np.array([1, 2, 3, 4, 5])

print(arr)

16. Program to Demonstrate NumPy Array Indexing

import numpy as np

arr = np.array([1, 2, 3, 4])

print(arr[1])

17. Program to Demonstrate NumPy Array Reshaping

import numpy as np

arr = np.array([1, 2, 3, 4, 5, 6])

newarr = arr.reshape(2, 3)

print(newarr)
18. Program to Demonstrate Math Module

import math

x = math.sqrt(64)

print(x)

19. Program to Demonstrate Pandas Series

import pandas as pd

data = [10, 20, 30, 40, 50]

series = pd.Series(data)

print(series)

20. Program to Demonstrate Pandas DataFrames

import pandas as pd

data = {

"Name": ["Alice", "Bob"],

"Age": [24, 27]

df = pd.DataFrame(data)
print(df)

21. Program to Demonstrate Matplotlib and Seaborn

import matplotlib.pyplot as plt

x = [1, 2, 3]

y = [4, 5, 6]

plt.plot(x, y)

plt.show()

22. Program to Demonstrate Line Charts

import matplotlib.pyplot as plt

x = [1, 2, 3]

y = [4, 5, 6]

plt.plot(x, y, marker='o')

plt.show()

23. Program to Demonstrate Bar Charts

import matplotlib.pyplot as plt


x = ["A", "B", "C"]

y = [10, 20, 30]

plt.bar(x, y)

plt.show()

24. Program to Demonstrate Pie Charts

import matplotlib.pyplot as plt

labels = ['A', 'B', 'C']

sizes = [10, 20, 30]

plt.pie(sizes, labels=labels)

plt.show()

25. Program to Demonstrate Scatter Plots

import matplotlib.pyplot as plt

x = [1, 2, 3, 4]

y = [2, 4, 6, 8]

plt.scatter(x, y)

plt.show()

You might also like