0% found this document useful (0 votes)
3 views37 pages

Python Programs SEC

Uploaded by

Dad's Princess
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)
3 views37 pages

Python Programs SEC

Uploaded by

Dad's Princess
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

Python Programs

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


Code: def largest(a,b,c):
if a>=b and a>=c:
print(" a is greatest number")
elif b>=c:
print("b is greatest number")
else:
print("c is greatest number")
a=int(input("enter 1st number:"))
b=int(input("enter 2nd number:"))
c=int(input("enter 3rd number:"))
largest(a,b,c)
Output:
enter 1st number:15
enter 2nd number:20
enter 3rd number:16
b is greatest number
2) Write a Program to display all prime numbers within an
interval
Code: lower_value = int(input ("Enter the Lowest Range Value: “))
upper_value = int(input ("Enter the Upper Range Value: "))
print ("The Prime Numbers in the range are: ")
for number in range (lower_value, upper_value+1):
if number > 1:
for i in range (2, number):
if (number % i) == 0:
break
else:
print (number)

Output:
Enter the Lowest Range Value: 16
Enter the Upper Range Value: 64
The Prime Numbers in the range are:
17
19
23
29
31
37
41
43
47
53
59
61
3) Write a program to swap two numbers without using a
temporary variable
Code:
def swap_numbers(a, b):
print(f"Before swapping: a = {a}, b = {b}")
# Swapping using arithmetic operations
a=a+b
b=a-b
a=a-b
print(f"After swapping: a = {a}, b = {b}")
a = int(input("Enter the first number (a): "))
b = int(input("Enter the second number (b): "))
swap_numbers(a, b)

Output:
Enter the first number (a): 16
Enter the second number (b): 19
Before swapping: a = 16, b = 19
After swapping: a = 19, b = 16
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 Operatorsviii) Identity Operators.
Code:
i) Arithmetic Operators
a = 10
b=3
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)

II) Relational Operators


a = 10
b=3
print("Equal:", a == b)
print("Not Equal:", a != b)
print("Greater than:", a > b)
print("Less than:", a < b)
print("Greater than or equal to:", a >= b)
print("Less than or equal to:", a <= b)

III) Assignment Operators


a = 10
a += 5
print("a=", a)

a -= 3
print("a -= 3:", a)

a *= 2
print("a *= 2:", a)
a /= 4
print("a /= 4:", a)

a %= 5
print("a %= 5:", a)

a **= 3
print("a **= 3:", a)

IV) Logical Operators


a = 10
b = 15
if a==b:
print("a and b:", a and b)
elif a!=b:
print("a or b:", a or b)
else:
print("not a:", not a)

V) Bitwise Operators
a = 10 #1010
b = 4 #100
print("a & b:", a & b)
print("a | b:", a | b)
print("a ^ b:", a ^ b)
print("~a:", ~a)
print("a << 2:", a << 2)
print("a >> 2:", a >> 2)

VI) Ternary Operator


a = 10
b = 20

min_val = a if a < b else b


print("Minimum value:", min_val)
VII) Membership Operators
a = [1, 2, 3, 4, 5]

print("3 in a:", 3 in a)
print("6 in a:", 6 in a)
print("6 not in a:", 6 not in a)

VIII) Identity Operators


a = 10
b = 20
c=a

print("a is b:", a is b)
print("a is c:", a is c)
Output:
Addition: 13
Subtraction: 7
Multiplication: 30
Division: 3.3333333333333335
Modulus: 1
Exponentiation: 1000
Floor Division: 3
Equal: False
Not Equal: True
Greater than: True
Less than: False
Greater than or equal to: True
Less than or equal to: False
a= 15
a -= 3: 12
a *= 2: 24
a /= 4: 6.0
a %= 5: 1.0
a **= 3: 1.0
Minimum value: 10
3 in a: True
6 in a: False
6 not in a: True
a or b: 10
a & b: 0
a | b: 14
a ^ b: 14
~a: -11
a << 2: 40
a >> 2: 2
a is b: False
a is c: True
5) Write a program to add and multiply complex numbers
Code:
first = complex(input('Enter first complex number: '))
second = complex(input('Enter second complex number: '))
# Addition of complex number
addition = first + second
print('SUM = ', addition)
#multiplication of two numbers
multiply = first * second
print("multiplication=",multiply)
Output:
Enter first complex number: 16+19j
Enter second complex number: 19+16j
SUM = (35+35j)
multiplication= 617j
6) Write a program to print multiplication table of a given number.
Code:
def table(n):
for i in range (1, 11):
# multiples from 1 to 10
print ("%d * %d = %d" % (n, i, n * i))
# number for which table is evaluated
n = int(input("enter a number:"))
table(n)

Output:
enter a number:6
6*1=6
6 * 2 = 12
6 * 3 = 18
6 * 4 = 24
6 * 5 = 30
6 * 6 = 36
6 * 7 = 42
6 * 8 = 48
6 * 9 = 54
6 * 10 = 60
1. Write a program to define a function with multiple return values.
Code:
def calculate(a, b):
# Perform some calculations
sum_result = a + b
difference = a - b
product = a * b
quotient = a / b if b != 0 else None # Handle division by zero

# Return multiple values


return sum_result, difference, product, quotient
a=int(input("enter a number:"))
b=int(input("Enter a Number:"))
# Call the function and store the results
result_sum, result_difference, result_product, result_quotient =
calculate(a, b)
# Print the results
print("Sum:", result_sum)
print("Difference:", result_difference)
print("Product:", result_product)
print("Quotient:", result_quotient)

Output:

1
2. Write a program to define a function using default arguments

Code:
# creatin a Function to display student information with
default values for grade and age
def display_student_info(name, grade="A", age=18):
print(f"Name: {name}")
print(f"Grade: {grade}")
print(f"Age: {age}")

# Calling the function with and without default arguments


display_student_info("Raj") # Uses default values for
grade and age
print()
display_student_info("Ram", "B", 20) # Overwrites default values

Output:

2
3. Write a program to find the length of the string without using any
library functions.
Code:
# Function to find the length of a string without using library
functions
def string(input_string):
length = 0
for char in input_string:
length += 1
return length

# Input string
my_string = "Hello, students!"

# Find the length of the string


length_of_string = string(my_string)

# Output the result


print(f"The length of the string is: {length_of_string}")

Output:

3
4. Write a program to check if the substring is present in a given string or
not
Code:

def substring(main_string, sub_string):


if sub_string in main_string:
return True
else:
return False
# Example usage
main_string = "Hello, students! Welcome to python class.."
sub_string = "python"
result = substring(main_string, sub_string)
if result:
print(f"'{sub_string}' is present in '{main_string}'")

else:
print(f"'{sub_string}' is not present in '{main_string}'")

Output:

4
5. Write a program to perform the given operations on a list:
i. addition ii. Insertion iii. slicing
Code:
# List operations: addition, insertion, and slicing
# Creating a list with 5 elements
my_list = [1, 2, 3, 4, 5]
# i. Addition - Adding an element to the list using append()
my_list.append(6)
print("After Addition:", my_list)
# ii. Insertion - Inserting an element at a specific index using insert()

my_list.insert(2, 10) # Inserting 10 at index 2


print("After Insertion:", my_list)
# iii. Slicing - Extracting a portion of the list
sliced_list = my_list[1:4] # Extract elements from index 1 to 3
print("Sliced List:", sliced_list)

Output:

5
6. Write a program to perform any 5 built-in functions by taking
any list.
Code:
# Creating a simple list with 6 elements
my_list = [10, 20, 30, 40, 50, 60]
# 1. append() - Adds an element to the end of the list
my_list.append(70)
print("After append(70):", my_list)
# 2. extend() - Extends the list by appending elements at
the end of the list
my_list.extend([80, 90])
print("After extend([80, 90]):", my_list)
# 3. insert() - Inserts an element at a specified index
my_list.insert(2, 25) # Inserting 25 at index 2
print("After insert(2, 25):", my_list)
# 4. remove() - Removes the first occurrence of a specified
value
my_list.remove(40)
print("After remove(40):", my_list)
# 5. pop() - Removes and returns the element at the
specified position (last element if no index is provided)
remove_element = my_list.pop() # Removes the last
element
print("After pop():", my_list)
print("Removed Element:", remove_element)
Output:

6
Unit-3 Programs
1. Write a program to create tuples (name, age, address, college) for at
least two members and concatenate the tuples and print the
concatenated tuples.

Code:
#creatin a tuple to fetch student details with tuples concept
student1=("rani",19,"etukuru","MLEW")
student2=("sita",20,"Guntur","KHITS")
#concatenating the above two tuples
details= student1 + student2
#now printing the concatenated tupe named details
print("the tuple after concatenation is:")
print(details)

OUTPUT:

1
2. Write a program to count the number of vowels in a string
(No control flow allowed)
Code:
# Input string
input_string = "This is a sample string with vowels."
# Use a lambda function with filter() to count vowels
vowels = "aeiouAEIOU"
count_vowels = len(list(filter(lambda char: char in vowels, input_string)))

# Print the result


print("Number of vowels in the string:", count_vowels)
filter(): This function filters elements from a sequence based on a condition. It
takes two arguments: a function (or lambda in this case) and the sequence to
filter.
lambda char: char in vowels: The lambda function checks if each character
(char) from the input_string is present in the vowels string. The lambda
expression returns True if the character is a vowel, and False otherwise.
Result of filter(): The filter() function returns an iterator containing only the
characters from the input_string that are vowels.
list(): The filter() iterator is converted to a list. This list will contain only the
vowels from the input_string.
len(): The length of this list (i.e., the number of vowels) is then calculated using
the len() function and stored in the variable count_vowels

OUTPUT:

2
3. Write a program to check if a given key exists in a dictionary or
not.

Code:
# Define a dictionary
mydict = {
"name": "shreshta",
"age": 22,
"city": "Guntur",
"college": "MLEW"
}
# Input: key to be checked
key = "name" # You can change this key to test
# Check if the key exists in the dictionary
if key in mydict:
print(f"Key '{key}' exists in the dictionary.")
else:
print(f"Key '{key}' does not exist in the dictionary.")

OUTPUT:

3
4. Write a program to add a new key-value pair to an
existing dictionary.

Code:
# creating a dictionary with key and value pair
sample_dict = {
"name": "shreshta",
"age": 22,
"city": "Guntur"
}
# New key-value pair to add
key = "college"
value = "MLEW"

# Add the new key-value pair to the dictionary


sample_dict[key] = value

# Print the updated dictionary


print("Updated Dictionary:")
print(sample_dict)

OUTPUT:

4
5. Write a program to sum all the items in a given
dictionary.

Code:
#creating a dictionary with numerical values
dict = {
1: 15,
2: 30,
3: 95,
4: 10
}

# Sum all the values in the dictionary


sums = sum([Link]())
sum1=sum([Link]())
# Print the result
print("The sum of all items in the dictionary is:", sums)
print("The sum of all keys in the dictionary is:", sum1)

OUTPUT:

5
UNIT-4 PROGRAMS
1. Write 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.
AIM: To write a program [Link] 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.
Program:
def sort_words_in_file(input_file, output_file):
try:
with open(input_file, 'r') as file:
words = [Link]().split()
lower_case_words = [[Link]() for word in words]
sorted_words = sorted(set(lower_case_words)) # Use set to avoid duplicates
with open(output_file, 'w') as file:
for word in sorted_words:
[Link](f"{word}\n")
print(f"Sorted words have been written to '{output_file}'.")
except FileNotFoundError:
print(f"The file '{input_file}' was not found.")
except Exception as e:
print(f"An error occurred: {e}")
input_file_name = '[Link]' # Source file with words
output_file_name = '[Link]' # Destination file for sorted words
sort_words_in_file(input_file_name, output_file_name)

[Link]:
shreshta
python lab
Skill Enhancement Course

[Link]:
course
enhancement
lab
python
shreshta
skill

Output:
2. Write a Python program to print each line of a file in reverse order.
AIM: To Write a python program to print each line of a file in reverse order.
Program:

with open("[Link]", "r") as file:


lines = [Link]()

for line in lines:


print([Link]()[::-1])
# Reverse the line and remove newline characters

[Link]:
Python is Fun
Learning to Code in Python
HELLO world
3. Write a Python program to compute the number of characters, words and lines in a file
AIM: To write a Python program to compute the number of characters, words and lines in a
file
Program:
with open("[Link]", "r") as file:
lines = [Link]()
num_lines = len(lines)
num_words = sum(len([Link]()) for line in lines)
num_chars = sum(len(line) for line in lines)
print(f"Lines: {num_lines}, Words: {num_words}, Characters:{num_chars}")

[Link]:
Python is Fun
Learning to Code in Python
HELLO world

OUTPUT:
4. Write a program to create, display, append, insert and reverse the order of the items
in the array.
AIM: To write a program to create, display, append, insert and reverse the order of the items
in the array.
Program:
from array import array
# Create an array of integers
arr = array('i', [1, 2, 3, 4, 5])
# Display array
print("Original array:", arr)
# Append a new item
[Link](6)
print("After appending:", arr)
# Insert an item at a specific position
[Link](2, 10)
print("After insertion:", arr)
# Reverse the array
[Link]()
print("Reversed array:", arr)

Output:
5. Write a program to add, transpose and multiply two matrices.
AIM: To write a program to add, transpose and multiply two matrices.
Program:
import numpy as np
# Create two matrices
A = [Link]([[1, 2], [3, 4]])
B = [Link]([[5, 6], [7, 8]])
# Add matrices
C=A+B
print("Addition:\n", C)
# Transpose a matrix
AT = A.T
print("Transpose of A:\n", AT)
# Multiply matrices
D = [Link](A, B)
print("Multiplication:\n", D)

Output:
6. Write a Python program to create a class that represents a shape. Include methods to
calculate its area and perimeter. Implement subclasses for different shapes like circle,
triangle, and square.
AIM: To write a Python program to create a class that represents a shape. Include methods
to calculate its area and perimeter. Implement subclasses for different shapes like circle,
triangle, and square.
Program:
class Shape:
def area(self):
pass
def perimeter(self):
pass
class Circle(Shape):
def __init__(self, radius):
[Link] = radius
def area(self):
return 3.14 * [Link] ** 2
def perimeter(self):
return 2 * 3.14 * [Link]
class Square(Shape):
def __init__(self, side):
[Link] = side
def area(self):
return [Link] ** 2
def perimeter(self):
return 4 * [Link]
# Example usage
circle = Circle(5)
square = Square(4)
print("Circle Area:", [Link]())
print("Circle Perimeter:", [Link]())
print("Square Area:", [Link]())
print("Square Perimeter:", [Link]())

OUTPUT:
UNIT-5
1) Write a python program to check whether a JSON string contains complex object or
not
AIM: To write a python program to check whether a JSON string contains complex object
or not
Program:
import json
def contains_complex_object(data):
if isinstance(data, dict):
for value in [Link]():
if isinstance(value, (dict, list)):
return True or contains_complex_object(value)
elif isinstance(data, list):
for item in data:
if isinstance(item, (dict, list)):
return True or contains_complex_object(item)
return False
# Example JSON strings
json_str1 = '{"name": "Alice", "age": 25, "city": "New York"}'
json_str2 = '{"name": "Alice", "address": {"city": "New York", "zip": 12345}}'
# Convert to Python objects
data1 = [Link](json_str1)
data2 = [Link](json_str2)
# Check for complex objects
print("JSON 1 contains complex object:", contains_complex_object(data1))
print("JSON 2 contains complex object:", contains_complex_object(data2))

OUTPUT:
2) Write a Python Program to demonstrate NumPy arrays creation using array ()
function
AIM: To Write a Python Program to demonstrate NumPy arrays creation using array
() function
Program:
# Importing the NumPy library
import numpy as np
# Creating a 1D array
arr1 = [Link]([10, 20, 30, 40, 50])
print("1D Array:")
print(arr1)
# Creating a 2D array
arr2 = [Link]([[1, 2, 3], [4, 5, 6]])
print("\n2D Array:")
print(arr2)
# Creating an array from a tuple
arr3 = [Link]((7, 8, 9, 10))
print("\nArray from Tuple:")
print(arr3)
# Creating an array with mixed data types
arr4 = [Link]([1, 2.5, 3, 4.7])
print("\nArray with Mixed Data Types:")
print(arr4)
# Displaying array data type and dimension
print("\nArray Properties:")
print("Type of arr1:", type(arr1))
print("Data Type of arr1 elements:", [Link])
print("Dimensions of arr2:", [Link])
print("Shape of arr2:", [Link])
OUTPUT:
3) Write a Python program to demonstrate use of ndim, shape, size, dtype.
4) AIM: To W Write a Python program to demonstrate use of ndim, shape, size,
dtype.
Program:
import numpy as np
# Create a NumPy array
arr = [Link]([[10, 20, 30], [40, 50, 60]])
# Display the array
print("Array:\n", arr)
# Number of dimensions (ndim)
print("\nNumber of dimensions (ndim):", [Link])
# Shape of the array (shape)
print("Shape of the array (shape):", [Link])
# Total number of elements (size)
print("Total number of elements (size):", [Link])
# Data type of each element (dtype)
print("Data type of elements (dtype):", [Link])

OUTPUT:
4)Write Python program to demonstrate basic slicing, integer and Boolean indexing.

AIM: To write a Python program to demonstrate basic slicing, integer and Boolean indexing

Program:

import numpy as np

# Create a sample NumPy array

arr = [Link]([10, 20, 30, 40, 50, 60, 70, 80])

print("Original Array:")

print(arr)

# Basic Slicing

print("\n1. Basic Slicing:")

print("Elements from index 2 to 5:", arr[2:6])

print("Every second element:", arr[::2])

print("Reversed array:", arr[::-1])

# Integer Indexing

print("\n2. Integer Indexing:")

indices = [0, 3, 5]

print("Elements at indices 0, 3, and 5:", arr[indices])

# Boolean Indexing

print("\n3. Boolean Indexing:")

bool_mask = arr > 40

print("Boolean mask (arr > 40):", bool_mask)

print("Elements greater than 40:", arr[bool_mask])

OUTPUT:
5) Write a Python program to find min, max, sum, cumulative sum of array
AIM: To write a Python program to find min, max, sum, cumulative sum of array
Program:
import numpy as np
# Create a NumPy array
arr = [Link]([10, 20, 30, 40, 50])
print("Original Array:")
print(arr)
# Find minimum element
min_value = [Link](arr)
print("\nMinimum value:", min_value)
# Find maximum element
max_value = [Link](arr)
print("Maximum value:", max_value)
# Find sum of all elements
sum_value = [Link](arr)
print("Sum of all elements:", sum_value)
# Find cumulative sum of elements
cumsum_value = [Link](arr)
print("Cumulative sum of elements:", cumsum_value)

OUTPUT:
6) Write a python program to Create a dictionary with at least five keys and each key
represent value as a list where this list contains at least ten values and convert
this dictionary as a pandas data frame and explore the data through the data
frame as follows:
a) Apply head() function to the pandas data frame
b) Perform various data selection operations on Data Frame
AIM: To create a dictionary with at least five keys where each key represents a list
containing ten values, convert this dictionary into a Pandas DataFrame, and explore
the data by applying the head() function and performing various data selection
operations using Pandas.
Program:
import pandas as pd
# Step 1: Create a dictionary with 5 keys and 10 values in each list
student_data = {
'Student_ID': [101, 102, 103, 104, 105, 106, 107, 108, 109, 110],
'Name': ['Arun', 'Bhavya', 'Chitra', 'Dinesh', 'Esha', 'Farhan', 'Gita', 'Hari', 'Indu',
'Jatin'],
'Age': [18, 19, 20, 21, 18, 22, 19, 20, 21, 22],
'Marks': [85, 78, 92, 66, 80, 75, 89, 90, 70, 88],
'City': ['Hyderabad', 'Chennai', 'Bangalore', 'Delhi', 'Mumbai', 'Pune', 'Kolkata',
'Chennai', 'Delhi', 'Hyderabad']
}
# Step 2: Convert dictionary to DataFrame
df = [Link](student_data)
print("Original DataFrame:")
print(df)
# Step 3: Apply head() function
print("\nFirst 5 rows using head():")
print([Link]())
# Step 4: Perform various data selection operations
# a) Selecting a single column
print("\nSelect 'Name' column:")
print(df['Name'])
# b) Selecting multiple columns
print("\nSelect 'Name' and 'Marks' columns:")
print(df[['Name', 'Marks']])
# c) Selecting specific rows using slicing
print("\nSelect rows from index 2 to 6:")
print(df[2:7])
# d) Selecting specific data using loc (label-based)
print("\nMarks of Student_ID 104:")
print([Link][3, 'Marks'])
# e) Selecting specific data using iloc (index-based)
print("\nCity of 6th student (index 5):")
print([Link][5, 4])
# f) Conditional selection (students with marks greater than 80)
print("\nStudents with Marks > 80:")
print(df[df['Marks'] > 80])
# g) Selecting rows and columns together
print("\nSelect 'Name' and 'City' of students with Age > 20:")
print([Link][df['Age'] > 20, ['Name', 'City']])

OUTPUT:

Original DataFrame:
Student_ID Name Age Marks City
0 101 Arun 18 85 Hyderabad
1 102 Bhavya 19 78 Chennai
2 103 Chitra 20 92 Bangalore
3 104 Dinesh 21 66 Delhi
4 105 Esha 18 80 Mumbai
5 106 Farhan 22 75 Pune
6 107 Gita 19 89 Kolkata
7 108 Hari 20 90 Chennai
8 109 Indu 21 70 Delhi
9 110 Jatin 22 88 Hyderabad

First 5 rows using head():


Student_ID Name Age Marks City
0 101 Arun 18 85 Hyderabad
1 102 Bhavya 19 78 Chennai
2 103 Chitra 20 92 Bangalore
3 104 Dinesh 21 66 Delhi
4 105 Esha 18 80 Mumbai

Select 'Name' column:


0 Arun
1 Bhavya
2 Chitra
3 Dinesh
4 Esha
5 Farhan
6 Gita
7 Hari
8 Indu
9 Jatin
Name: Name, dtype: object

Select 'Name' and 'Marks' columns:


Name Marks
0 Arun 85
1 Bhavya 78
2 Chitra 92
3 Dinesh 66
4 Esha 80
5 Farhan 75
6 Gita 89
7 Hari 90
8 Indu 70
9 Jatin 88

Select rows from index 2 to 6:


Student_ID Name Age Marks City
2 103 Chitra 20 92 Bangalore
3 104 Dinesh 21 66 Delhi
4 105 Esha 18 80 Mumbai
5 106 Farhan 22 75 Pune
6 107 Gita 19 89 Kolkata

Marks of Student_ID 104:


66

City of 6th student (index 5):


Pune

Students with Marks > 80:


Student_ID Name Age Marks City
0 101 Arun 18 85 Hyderabad
2 103 Chitra 20 92 Bangalore
6 107 Gita 19 89 Kolkata
7 108 Hari 20 90 Chennai
9 110 Jatin 22 88 Hyderabad

Select 'Name' and 'City' of students with Age > 20:


Name City
3 Dinesh Delhi
5 Farhan Pune
8 Indu Delhi
9 Jatin Hyderabad
[Link] a python program to 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
AIM: To write a python program to observe the change in one attribute with respect to other
attribute with scatter and plot operations in matplotlib.
Program:
import pandas as pd
import [Link] as plt

# Step 1: Create a dictionary with 5 keys and 10 values in each list


student_data = {
'Student_ID': [101, 102, 103, 104, 105, 106, 107, 108, 109, 110],
'Name': ['Arun', 'Bhavya', 'Chitra', 'Dinesh', 'Esha', 'Farhan', 'Gita', 'Hari', 'Indu', 'Jatin'],
'Age': [18, 19, 20, 21, 18, 22, 19, 20, 21, 22],
'Marks': [85, 78, 92, 66, 80, 75, 89, 90, 70, 88],
'City': ['Hyderabad', 'Chennai', 'Bangalore', 'Delhi', 'Mumbai', 'Pune', 'Kolkata', 'Chennai', 'Delhi',
'Hyderabad']
}

# Step 2: Convert dictionary to DataFrame


df = [Link](student_data)

# Display the DataFrame


print("Data Frame:")
print(df)

# Step 3: Select two columns: Age and Marks


x = df['Age']
y = df['Marks']

# Step 4: Scatter plot - to observe relation between Age and Marks


[Link](x, y, color='blue', marker='o')
[Link]('Scatter Plot - Age vs Marks')
[Link]('Age')
[Link]('Marks')
[Link](True)
[Link]()

# Step 5: Line plot - to observe trend between Age and Marks


[Link](x, y, color='green', marker='o')
[Link]('Line Plot - Age vs Marks')
[Link]('Age')
[Link]('Marks')
[Link](True)
[Link]()

OUTPUT:

You might also like