pythonteamppt[1]
pythonteamppt[1]
on
SKILL ENHANCEMENT COURSE – I (Course Code:
V23CSSE01)
B.TECH III Semester (2023 - 2027 Batch )
Academic Year: 2024-25
Examiner1 Examiner2
INDEX
Page No's
S.No. Name of the Topic
(From-to)
1. Introduction to Python
2. List of Experiments
PROJECT
i. Abstract
v. Conclusion
1
Introduction to Python
Python is a high-level, versatile programming language known for its simplicity and
readability. Created by Guido van Rossum and first released in 1991, Python has grown to
become one of the most popular programming languages due to its easy-to-read syntax,
dynamic typing, and strong community support. Python’s clear structure and rich library
ecosystem make it a great choice for both beginners and experienced developers.
Uses of Python
1.Web Development: Python offers powerful frameworks like Django, Flask, and FastAPI
that simplify the development of dynamic websites and backend services by providing tools
for database interaction, user authentication, and URL routing.
2.Data Science and Machine Learning: Python is widely used for data analysis, scientific
computing, and machine learning. Libraries like NumPy, Pandas, Matplotlib, TensorFlow,
and scikit-learn make it easy to perform data manipulation, build predictive models, and
visualize complex datasets.
3.Automation and Scripting: Python is a popular choice for scripting and automating
repetitive tasks, such as file manipulation, data extraction, and report generation. IT
professionals and system administrators use Python to streamline workflows and improve
efficiency.
4.Artificial Intelligence (AI) and Deep Learning: Python has become the go-to language
for AI and deep learning due to libraries like Keras, PyTorch, and TensorFlow, which offer
pre-built tools for neural networks and deep learning model development.
5.Game Development: Basic game development is possible with Python through libraries
like Pygame, which allows for the creation of 2D games, interactive applications, and
multimedia projects.
6.Desktop GUI Applications: Python’s libraries such as Tkinter, PyQt, and Kivy allow
developers to build cross-platform desktop applications with graphical user interfaces.
7.Networking and Cybersecurity: Python is also widely used in networking for scripting
network devices and in cybersecurity for tasks like penetration testing and vulnerability
assessment, leveraging libraries like Scapy and Nmap.
Python’s ease of use, flexibility, and extensive library support make it ideal for various fields,
from web development to scientific research. Its popularity grows as developers embrace it
for both simple scripts and large-scale applications.
2
List of Experiments as per Syllabus:
Output:
Enter first number: 15
Enter second number: 20
Enter third number: 25
The largest number is: 25.0
Output:
Enter the lower bound: 1
Enter the upper bound: 10
12357
3
3. Develop a program to swap two numbers without using a temporary
variable.
x=x+y
y=x-y
x=x-y
print("After swapping:")
print("First number:", x)
print("Second number:", y)
Output:
Enter first number: 15
Enter second number: 100
After swapping:
First number: 100.0
Second number: 15.0
# Relational Operators
print("Equal:", a == b)
print("Not Equal:", a != b)
print("Greater than:", a > b)
print("Less than:", a < b)
print("Greater or equal:", a >= b)
4
print("Less or equal:", a <= b)
# Assignment Operators
c=a+b
print("Assigned value:", c)
c += 3
print("After c += 3:", c)
c *= 3
print("After c *= 3:", c)
# Logical Operators
print("Logical AND:", a > 10 and b > 1)
print("Logical OR:", a > 10 or b > 10)
print("Logical NOT:", not (a < b))
# Bitwise Operators
print("Bitwise AND:", a & b)
print("Bitwise OR:", a | b)
print("Bitwise XOR:", a ^ b)
print("Bitwise NOT:", ~a)
print("Left Shift:", a << 2)
print("Right Shift:", a >> 2)
# Ternary Operator
result = "a is greater" if a > b else "b is greater"
print("Ternary Result:", result)
# Membership Operators
list_example = [10, 20, 30, 40, 50]
print("Is 20 in list?", 20 in list_example)
print("Is 60 not in list?", 60 not in list_example)
# Identity Operators
x = [5, 10, 15]
y=x
z = [5, 10, 15]
print("Is x identical to y?", x is y)
print("Is x identical to z?", x is z)
5
Output:
Addition: 19
Subtraction: 11
Multiplication: 60
Division: 3.75
Modulus: 3
Exponentiation: 50625
Floor Division: 3
Equal: False
Not Equal: True
Greater than: True
Less than: False
Greater or equal: True
Less or equal: False
Assigned value: 19
After c += 3: 22
After c *= 3: 66
Logical AND: True
Logical OR: True
Logical NOT: True
Bitwise AND: 4
Bitwise OR: 15
Bitwise XOR: 11
Bitwise NOT: -16
Left Shift: 60
Right Shift: 3
Ternary Result: a is greater
Is 20 in list? True
Is 60 not in list? True
Is x identical to y? True
Is x identical to z? False
5. Develop a program to add and multiply complex numbers
add_result = a + b
multiply_result = a * b
6
Output:
Enter first complex number: 5+2j
Enter second complex number: 3+4j
Addition of complex numbers: (8+6j)
Multiplication of complex numbers: (7+26j)
Output:
Enter a number: 10
10 x 1 = 10
10 x 2 = 20
10x 3 = 30
10 x 4 = 40
10x 5 = 50
10 x 6 = 60
10 x 7 = 70
10 x 8 = 80
10 x 9 = 90
10x 10 = 100
Output:
Addition: 13
Subtraction: 3
Multiplication: 40
7
8. Develop a program to define a function using default arguments.
print(greet(“Ram"))
print(greet(“Ravi", "Hello"))
Output:
Hii, Ram
Hello, Ravi
9. Develop a program to find the length of the string without using any
library functions.
def find_length(string):
count = 0
for char in string:
count += 1
return count
print("Length:", find_length(“program"))
Output:
Length: 7
Output:
Yes, the substring is found!
No, the substring is not found.
8
11. Develop a program to perform the given operations on a list: i.
addition ii. Insertion iii. Slicing
numbers.insert(3, 99)
print("After insertion:", numbers)
sliced_list = numbers[2:5]
print("Sliced list:", sliced_list)
Output:
After addition: [10, 20, 30, 40, 50, 60]
After insertion: [10, 20, 30, 99, 40, 50, 60]
Sliced list: [30, 99, 40]
Output:
Length: 5
Maximum: 15
Minimum: 3
Sum: 44
Sorted: [3, 6, 8, 12, 15]
13. Develop a program to create tuples (name, age, address, college) for
at least two members and concatenate the tuples and print the
concatenated tuples
9
member1 = ("John", 25, "789 Boulevard", "LMN University")
member2 = ("Emma", 28, "1010 Road", "PQR College")
Output:
Concatenated tuple: ('John', 25, '789 Boulevard', 'LMN University', 'Emma', 28, '1010
Road', 'PQR College')
Output:
Number of vowels: 4
Output:
Key exists in the dictionary.
10
new_value = "USA"
my_dict[new_key] = new_value
print("Updated dictionary:", my_dict)
Output:
Updated dictionary: {'name': 'Bob', 'city': 'New York', 'country': 'USA'}
17. Develop a program to sum all the items in a given dictionary.
Output:
Sum of all items: 75
18. Develop a program to sort words in a file and put them in another
file. The output file should have only lower-case words, so any upper-
case words from source must be lowered.
Output:
Words sorted in reverse and saved to sorted_data.txt
19. Develop a Python program to print each line of a file in reverse order.
11
Output:
esrevinU olleH
skcoR ecneicS ataD
droW hcaE esreveR
line_count = len(lines)
word_count = sum(len(line.split()) for line in lines)
char_count = sum(len(line) for line in lines)
print("Lines:", line_count)
print("Words:", word_count)
print("Characters:", char_count)
Output:
Lines: 3
Words: 6
Characters: 48
21. Develop a program to create, display, append, insert and reverse the
order of the items in the array.
12
22. Develop a program to add, transpose and multiply two matrices.
import numpy as np
sum_matrix = A + B
transpose_A = np.transpose(A)
product_matrix = np.dot(A, B)
Output:
Sum of matrices:
[[ 8 10]
[12 14]]
Transpose of A:
[[2 4]
[3 5]]
Product of matrices:
[[38 43]
[64 73]]
class Shape:
def area(self):
return 0
def perimeter(self):
return 0
class Circle(Shape):
def __init__(self, radius):
self.radius = radius
13
def area(self):
return math.pi * self.radius ** 2
def perimeter(self):
return 2 * math.pi * self.radius
class Square(Shape):
def __init__(self, side):
self.side = side
def area(self):
return self.side ** 2
def perimeter(self):
return 4 * self.side
class Triangle(Shape):
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c
def area(self):
s = (self.a + self.b + self.c) / 2
return math.sqrt(s * (s - self.a) * (s - self.b) * (s - self.c))
def perimeter(self):
return self.a + self.b + self.c
circle = Circle(7)
print("Circle - Area:", circle.area(), "Perimeter:", circle.perimeter())
square = Square(5)
print("Square - Area:", square.area(), "Perimeter:", square.perimeter())
Output:
Circle - Area: 153.93804002589985 Perimeter: 43.982297150257104
Square - Area: 25 Perimeter: 20
Triangle - Area: 24.0 Perimeter: 24
14
24. Develop a Python program to check whether a JSON string contains
complex object or not.
import json
def is_complex_object(json_string):
try:
obj = json.loads(json_string)
for key, value in obj.items():
if isinstance(value, (list, dict)):
return True
return False
except json.JSONDecodeError:
return False
Output:
Contains complex object: True
import numpy as np
Output:
1D array: [10 20 30 40 50]
2D array: [[ 7 8 9] [10 11 12]]
3D array:
15
[[[13 14]
[15 16]]
[[17 18]
[19 20]]]
import numpy as np
Output:
Array:
[[ 7 8 9]
[10 11 12]]
Number of dimensions: 2
Shape of array: (2, 3)
Size of array: 6
Data type of array elements: int32
import numpy as np
sliced_array = array[2:5]
print("Sliced array:", sliced_array)
16
Output:
Array: [15 25 35 45 55 65]
Sliced array: [35 45 55]
Integer indexed array: [15 35 65]
Boolean indexed array: [15 25 35 45]
28. Develop a Python program to find min, max, sum, cumulative sum of
array
import numpy as np
print("Minimum:", np.min(array))
print("Maximum:", np.max(array))
print("Sum:", np.sum(array))
print("Cumulative Sum:", np.cumsum(array))
Output:
Array: [10 20 30 40 50]
Minimum: 10
Maximum: 50
Sum: 150
Cumulative Sum: [ 10 30 60 100 150]
29. Prepare a dictionary with at least five keys and each key represent
value as a list where this list
import pandas as pd
data = {
"A": [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],
"B": [55, 60, 65, 70, 75, 80, 85, 90, 95, 100],
"C": [105, 110, 115, 120, 125, 130, 135, 140, 145, 150],
"D": [155, 160, 165, 170, 175, 180, 185, 190, 195, 200],
"E": [205, 210, 215, 220, 225, 230, 235, 240, 245, 250]
}
df = pd.DataFrame(data)
print("Data Frame:\n", df)
17
print("\nHead of DataFrame:\n", df.head())
selected_data = df[["A", "B"]]
print("\nSelected Data:\n", selected_data)
Output:
Data Frame:
A B C D E
0 5 55 105 155 205
1 10 60 110 160 210
2 15 65 115 165 215
3 20 70 120 170 220
4 25 75 125 175 225
5 30 80 130 180 230
6 35 85 135 185 235
7 40 90 140 190 240
8 45 95 145 195 245
9 50 100 150 200 250
Head of DataFrame:
A B C D E
0 5 55 105 155 205
1 10 60 110 160 210
2 15 65 115 165 215
3 20 70 120 170 220
4 25 75 125 175 225
Selected Data:
A B
0 5 55
1 10 60
2 15 65
3 20 70
4 25 75
5 30 80
6 35 85
7 40 90
8 45 95
9 50 100
30. Select any two columns from the above data frame, and observe the
change in one attribute with respect to other attribute with scatter and
plot operations in matplotlib.
18
import matplotlib.pyplot as plt
import pandas as pd
data = {
"A": [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],
"B": [20, 19, 18, 17, 16, 15, 14, 13, 12, 11],
"C": [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],
"D": [21, 23, 25, 27, 29, 31, 33, 35, 37, 39],
"E": [41, 43, 45, 47, 49, 51, 53, 55, 57, 59]
}
df = pd.DataFrame(data)
x = df["A"]
y = df["B"]
print("Data for plotting:")
print("Column A values:", list(x))
print("Column B values:", list(y))
# Scatter Plot
print("\nGenerating Scatter Plot of A vs B...")
plt.scatter(x, y, color="blue")
plt.title("Scatter Plot of A vs B")
plt.xlabel("A")
plt.ylabel("B")
plt.show()
print("Scatter Plot displayed.")
# Line Plot
print("\nGenerating Line Plot of A vs B...")
plt.plot(x, y, color="green", marker="o")
plt.title("Line Plot of A vs B")
plt.xlabel("A")
plt.ylabel("B")
plt.show()
print("Line Plot displayed.")
Output:
Data for plotting:
Column A values: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Column B values: [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
Generating Scatter Plot of A vs B...
Scatter Plot displayed.
Generating Line Plot of A vs B...
Line Plot displayed.
19