0% found this document useful (0 votes)
10 views

pythonteamppt[1]

Uploaded by

abbinalavanya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

pythonteamppt[1]

Uploaded by

abbinalavanya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

REPORT

on
SKILL ENHANCEMENT COURSE – I (Course Code:
V23CSSE01)
B.TECH III Semester (2023 - 2027 Batch )
Academic Year: 2024-25

SRI VASAVI ENGINEERING COLLEGE (Autonomous)


Pedatadepalli , Tadepalligudem - 534101
Department of Computer Science & Engineering (Accredited by NBA)
SRI VASAVI ENGINEERING COLLEGE (Autonomous)
PEDATADEPALLI, TADEPALLIGUDEM.

This is to certify Mr./Ms. bearing Roll No. of CSE


Branch of III Semester submitted the Report on as a part of SKILL
ENHANCEMENT COURSE - I (Course Code: V23CSSE01) during the academic year 2024-25.

Faculty In charge Head of the Department

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

ii. Objectives of the project


3.
iii. Software and Hardware Requirements

iv. Screenshots of the Project

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:

1.Develop a program to find the largest element among three Numbers

a = float(input("Enter first number: "))


b = float(input("Enter second number: "))
c = float(input("Enter third number: "))

if a >= b and a >= c:


largest = a
elif b >= a and b >= c:
largest = b
else:
largest = c

print("The largest number is:", largest)

Output:
Enter first number: 15
Enter second number: 20
Enter third number: 25
The largest number is: 25.0

2. Develop a Program to display all prime numbers within an interval

lower = int(input("Enter the lower bound: "))


upper = int(input("Enter the upper bound: "))

for num in range(lower, upper + 1):


if num > 1:
for i in range(2, num):
if num % i == 0:
break
else:
print(num, end=" ")

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 = float(input("Enter first number: "))


y = float(input("Enter second number: "))

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

4. Demonstrate the following Operators in Python with suitable examples.


i) Arithmetic Operators ii) Relational Operators iii) Assignment Operators
iv) Logical Operators v) Bit wise Operators vi) Ternary Operator vii)
Membership Operators viii) Identity Operators
# Arithmetic Operators
a = 15
b=4
print("Addition:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
print("Division:", a / b)
print("Modulus:", a % b)
print("Exponentiation:", a ** b)
print("Floor Division:", a // b)

# 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

a = complex(input("Enter first complex number: "))


b = complex(input("Enter second complex number: "))

add_result = a + b
multiply_result = a * b

print("Addition of complex numbers:", add_result)


print("Multiplication of complex numbers:", multiply_result)

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)

6. Develop a program to print multiplication table of a given number.

num = int(input("Enter a number: "))


for i in range(1, 11):
print(num, "x", i, "=", num * i)

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

7. Develop a program to define a function with multiple return values.

def calculate(a, b):


add = a + b
subtract = a - b
multiply = a * b
return add, subtract, multiply
result = calculate(8, 5)
print("Addition:", result[0])
print("Subtraction:", result[1])
print("Multiplication:", result[2])

Output:
Addition: 13
Subtraction: 3
Multiplication: 40

7
8. Develop a program to define a function using default arguments.

def greet(name, message="Hii"):


return message + ", " + name

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

10. Develop a program to check if the substring is present in a given


string or not.

def contains_substring(main_string, sub_string):


if sub_string in main_string:
return "Yes, the substring is found!"
else:
return "No, the substring is not found."

print(contains_substring("Hello, world!", "world"))


print(contains_substring("Hello, world!", "Python"))

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 = [10, 20, 30, 40, 50]


numbers.append(60)
print("After addition:", numbers)

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]

12. Develop a program to perform any 5 built-in functions by taking any


list.

sample_list = [15, 8, 3, 12, 6]


print("Length:", len(sample_list))
print("Maximum:", max(sample_list))
print("Minimum:", min(sample_list))
print("Sum:", sum(sample_list))
print("Sorted:", sorted(sample_list))

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

member1 = ("John", 25, "789 Boulevard", "LMN University")

9
member1 = ("John", 25, "789 Boulevard", "LMN University")
member2 = ("Emma", 28, "1010 Road", "PQR College")

concatenated = member1 + member2


print("Concatenated tuple:", concatenated)

Output:
Concatenated tuple: ('John', 25, '789 Boulevard', 'LMN University', 'Emma', 28, '1010
Road', 'PQR College')

14. Develop a program to count the number of vowels in a string (No


control flow allowed).

string = "Good Morning"


vowels = "aeiouAEIOU"
vowels_count = sum(string.count(vowel) for vowel in vowels)

print("Number of vowels:", vowels_count)

Output:
Number of vowels: 4

15. Develop a program to check if a given key exists in a dictionary or


not.

my_dict = {"name": "Bob", "city": "New York"} key = "city"


if key in my_dict:
print("Key exists in the dictionary.")
else:
print("Key does not exist in the dictionary.")

Output:
Key exists in the dictionary.

16. Develop a program to add a new key-value pair to an existing


dictionary.
my_dict = {"name": "Bob", "city": "New York"}
new_key = "country"

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.

my_dict = {"x": 15, "y": 25, "z": 35}


total = 0
for value in my_dict.values():
total += value
print("Sum of all items:", total)

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.

with open("data.txt", "r") as file:


words = file.read().split()
words = [word.upper() for word in words]
words.sort(reverse=True)
with open("sorted_data.txt", "w") as file:
for word in words:
file.write(word + "\n")
print("Words sorted in reverse and saved to sorted_data.txt")

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.

with open("input.txt", "r") as file:


lines = file.readlines()
for line in lines:
print(line[::-1].strip()) # Reverses each line and removes trailing spaces

11
Output:
esrevinU olleH
skcoR ecneicS ataD
droW hcaE esreveR

20. Develop a Python program to compute the number of characters,


words and lines in a file.

with open("input.txt", "r") as file:


lines = file.readlines()

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.

from array import array


arr = array("i", [7, 8, 9, 10, 11])
print("Array:", arr)
arr.append(12)
print("After appending:", arr)
arr.insert(3, 15)
print("After inserting:", arr)
arr.reverse()
print("Reversed array:", arr)
Output:
Array: array('i', [7, 8, 9, 10, 11])
After appending: array('i', [7, 8, 9, 10, 11, 12])
After inserting: array('i', [7, 8, 9, 15, 10, 11, 12])
Reversed array: array('i', [12, 11, 10, 15, 9, 8, 7])

12
22. Develop a program to add, transpose and multiply two matrices.

import numpy as np

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


B = np.array([[6, 7], [8, 9]])

sum_matrix = A + B
transpose_A = np.transpose(A)
product_matrix = np.dot(A, B)

print("Sum of matrices:\n", sum_matrix)


print("Transpose of A:\n", transpose_A)
print("Product of matrices:\n", product_matrix)

Output:
Sum of matrices:
[[ 8 10]
[12 14]]
Transpose of A:
[[2 4]
[3 5]]
Product of matrices:
[[38 43]
[64 73]]

23. Develop a Python program to create a class that represents a shape.


Include methods tocalculate its area and perimeter. Implement
subclasses for different shapes like circle, triangle, and square.
import math

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())

triangle = Triangle(6, 8, 10)


print("Triangle - Area:", triangle.area(), "Perimeter:", triangle.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

json_string = '{"name": "Alice", "address": {"city": "Wonderland", "zip": "12345"}}'


print("Contains complex object:", is_complex_object(json_string))

Output:
Contains complex object: True

25. Demonstrate NumPy arrays creation using array () function.

import numpy as np

array1 = np.array([10, 20, 30, 40, 50])


print("1D array:", array1)

array2 = np.array([[7, 8, 9], [10, 11, 12]])


print("2D array:\n", array2)

array3 = np.array([[[13, 14], [15, 16]], [[17, 18], [19, 20]]])


print("3D array:\n", array3)

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]]]

26. Demonstrate use of ndim, shape, size, dtype.

import numpy as np

array = np.array([[7, 8, 9], [10, 11, 12]])


print("Array:\n", array)

print("Number of dimensions:", array.ndim)


print("Shape of array:", array.shape)
print("Size of array:", array.size)
print("Data type of array elements:", array.dtype)

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

27. Demonstrate basic slicing, integer and Boolean indexing.

import numpy as np

array = np.array([15, 25, 35, 45, 55, 65])


print("Array:", array)

sliced_array = array[2:5]
print("Sliced array:", sliced_array)

indexed_array = array[[0, 2, 5]]


print("Integer indexed array:", indexed_array)

bool_indexed_array = array[array < 50]


print("Boolean indexed array:", bool_indexed_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

array = np.array([10, 20, 30, 40, 50])


print("Array:", array)

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

You might also like