INDEX
Teacher
[Link]. Date signature
1. Write a python program to find the largest number among
three number.
2. Write a python program to accept three sides of a triangle
as input and print whether the triangle is valid or not.
3. Write a program to check if the given number is a
palindrome number.
4. Write a program to reverse a user entered number and
determine whether the original and reversed numbers are
equal or not.
5. Write a program to count the number of alphabets and
number of digits in a string.
6. Write a program to accept a string from the user, delete all
vowels from the string and display the result.
7. Given a string, write a python program to find the largest
substring of uppercase characters and print the length of
that string.
8. Write a program to create following 3 lists:
A list of names ,A list of employee’s ids,A list of salaries
From lists,generate 3 tuples- one consisting all names,
another containing ids and third containing all
[Link], from the three created lists, generate and
print a list of tuples containing names, ids and salaries.
9. Write a program to create a set containing 10 randomly
generated numbers in the range 15 to 45. Count how many
of these numbers are less than 30. Delete all numbers
which are greater than 35.
10. Write a program to check whether an element exists within
a tuple.
11. Create a dictionary of 10 usernames and passwords . Receive
the username and password from keyboard and search for
them in dictionary. Print appropriate message on the screen
based on whether a match is found or not.
12. Write a program that defines a function compute( ) that
calculates the value of n+nn+nnn+nnnn, where n is digit
received by the function. Test the function for digit 4 and 7.
13. Create a lambda function ‘greater’, which takes two arguments
x and y and return x if x>y otherwise y.
14. Write a python program to demonstrate the use of lambda
functions with map,filter, and reduce.
15. Write a python program to handle a Zero Division Error
exception when dividing a number by zero.
16. Write a python program that prompts the user to input an
integer and raises a Value Error exception if the input is not a
valid integer.
17. Write a python program to create a numpy array of given
shape and perform mathematical operations.
18. Write a python program to perform groupby and aggregation
on a pandas dataframe.
19. Create Box plot, Scatter plot, and Histogram with Matplotlib.
20. Create Pair plot, Heatmap, and Distribution plot with
Seaborn.
OUTPUT:
Program 1
Write a python program to find the largest number
among three number.
num1 = int(input("enter the first number:"))
num2 = int(input("enter the second number:"))
num3 = int(input("enter the third number:"))
if (num1>=num2) and (num1>=num3):
print("largest number is:",num1)
elif (num2>=num1) and (num2>=num3):
print("largest number is:",num2)
else:
print("largest number is:",num3)
OUTPUT:
Program 2
Write a python program to accept three sides of a
triangle as input and print whether the triangle is
valid or not.
side1 = int(input("enter the first side :"))
side2 = int(input("enter the second side :"))
side3 = int(input("enter the third side :"))
if (side1+side2>=side3) and (side2+side3>=side1) and
(side1+side3>=side2):
print("triangle is valid")
else:
print("triangle is not valid")
OUTPUT:
Program 3
Write a program to check if the given number is a
palindrome number.
a=int(input('enter the number:'))
b=str(a)
if b==b[ : :-1]:
print('number is palindrome')
else:
print('number is not palindrome')
OUTPUT:
Program 4
Write a program to reverse a user entered number
and determine whether the original and reversed
numbers are equal or not.
num=int(input('enter the number:'))
rev=0
temp=num
while temp>0:
digit=temp%10
rev=rev*10+digit
temp//=10
print('reversed number:',rev)
if num==rev:
print('original and reversed numbers are equal')
else:
print('original and reversed numbers are not equal')
OUTPUT:
Program 5
Write a program to count the number of alphabets
and number of digits in a string.
s=input('enter the string:')
alphabet=0
digit=0
for i in s:
if [Link]():
alphabet+=1
elif [Link]():
digit+=1
print('number of alphabets=',alphabet)
print('number of digits=',digit)
OUTPUT:
Program 6
Write a program to accept a string from the user,
delete all vowels from the string and display the result.
s=input("enter a string:")
vowels="aeiouAEIOU"
result=""
for char in s:
if char not in vowels:
result+=char
print("string without vowels:",result)
OUTPUT:
Program 7
Given a string, write a python program to find the
largest substring of uppercase characters and print
the length of that string.
s=input("enter a string:")
max_len=0
curr_len=0
for char in s:
if [Link]():
curr_len+=1
if curr_len>max_len:
max_len=curr_len
else:
curr_len=0
print("largest uppercase substring length:",max_len)
OUTPUT:
Program 8
Write a program to create following 3 lists:
A list of names
A list of employee’s ids
A list of salaries
From lists,generate 3 tuples- one consisting all names,
another containing ids and third containing all
[Link], from the three created lists, generate and
print a list of tuples containing names, ids and salaries.
names=[]
ids=[]
salaries=[]
n=int(input("enter number of employees:"))
for i in range(n):
name=input("enter the name:")
emp_id=int(input("enter id:"))
salary=float(input("enter salary:"))
[Link](name)
[Link](emp_id)
[Link](salary)
name_tuple=tuple(names)
id_tuple=tuple(ids)
salary_tuple=tuple(salaries)
employee_data=[]
for i in range(n):
employee_data.append((names[i],ids[i],salaries[i]))
print("Tuples:",name_tuple,id_tuple,salary_tuple)
print("Employee data",employee_data)
OUTPUT:
Program 9
Write a program to create a set containing 10
randomly generated numbers in the range 15 to 45.
Count how many of these numbers are less than 30.
Delete all numbers which are greater than 35.
import random
random_numbers={[Link](15,40) for i in range(20)}
print("generated set:",random_numbers)
count_less_than_30=sum(num<30 for num in random_numbers)
print("count of numbers less than 30:",count_less_than_30)
random_numbers=(num for num in random_numbers if
num<=35)
print("set after deleting numbers greater than
35:",random_numbers)
OUTPUT:
Program 10
Write a program to check whether an element exists
within a tuple.
T=(20,40,60,80,100,120,140,160,180,200)
element=int(input("enter the element:"))
if element in T:
print("element exist in tuple.")
else:
print("element not exist in tuple.")
OUTPUT:
Program 11
Create a dictionary of 10 usernames and passwords .
Receive the username and password from keyboard
and search for them in dictionary. Print appropriate
message on the screen based on whether a match is
found or not.
user_db = {
"user1": "us234",
"user2": "ase423",
"user3": "chv25",
"user4": "dss765",
"user5": "edsd399",
"user6": "Fio4526",
"user7": "Gety3424",
"user8": "Hnn321",
"user9": "Iva9756",
"user10": "Jgyaf6587"
}
print("For login:")
username = input("Enter username: ")
password = input("Enter password: ")
if username in user_db:
if user_db[username] == password:
print("Login successful!")
else:
print("Incorrect password.")
else:
print("Username not found.")
OUTPUT:
Program 12
Write a program that defines a function compute( )
that calculates the value of n+nn+nnn+nnnn, where n
is digit received by the function. Test the function for
digit 4 and 7.
def compute(n):
n_str=str(n)
total=int(n_str)+int(n_str*2)+int(n_str*3)+int(n_str*4)
return total
print("result for n=4:",compute(4))
print("result for n=7:",compute(7))
OUTPUT:
Program 13
Create a lambda function ‘greater’, which takes two
arguments x and y and return x if x>y otherwise y.
greater=lambda x,y:x if x>y else y
x=float(input("Enter the value of x:"))
y=float(input("Enter the value of y:"))
print("The greatest value from ",x," and ",y," is:",greater(x,y))
OUTPUT:
Program 14
Write a python program to demonstrate the use of
lambda functions with map,filter, and reduce.
from functools import reduce
numbers=[1,2,3,4,5,6,7,8]
squared=list(map(lambda x:x**2,numbers))
print("Squares of numbers:",squared)
evens=list(filter(lambda x:x%2==0,numbers))
print("Even numbers:",evens)
sum_all=reduce(lambda x,y:x+y,numbers)
print("Sum of all numbers:",sum_all)
OUTPUT:
Program 15
Write a python program to handle a Zero Division
Error exception when dividing a number by zero.
try:
numerator=float(input("enter numerator:"))
denominator=float(input("enter denominator:"))
result=numerator/denominator
except ZeroDivisionError:
print("Error: cannot divide by zero.")
else:
print("Result:",result)
finally:
print("execution completed")
OUTPUT:
Program 16
Write a python program that prompts the user to
input an integer and raises a Value Error exception if
the input is not a valid integer.
try:
num=int(input("Enter an integer:"))
print("you entered:",num)
except ValueError:
print("error:invalid [Link] enter a valid integer.")
OUTPUT:
Program 17
Write a python program to create a numpy array of
given shape and perform mathematical operations.
import numpy as np
rows=int(input("Enter no. of rows:"))
cols=int(input("Enter no. of columns:"))
shape=(rows,cols)
array=[Link](1,101,size=shape)
print("Array is:\n",array)
add=array+2
print("Addition is:\n",add)
sub=array-2
print("Subtraction is:\n",sub)
mul=array*2
print("Multiply is:\n",mul)
div=array/2
print("Division is:\n",div)
OUTPUT:
Program 18
Write a python program to perform groupby and
aggregation on a pandas dataframe.
import pandas as pd
data={'Department':['HR','HR','IT','IT','FINANCE'],
'Employee':['A','B','C','D','E'],
'Salary':[600,200,300,400,500]
}
a=[Link](data)
print(a)
grouping=[Link]('Department').agg({'Salary':['mean','max','
min']})
print(grouping)
OUTPUT:
Program 19
Create a Box plot, Scatter plot and Histogram with
matplotlib.
Box plot:
import [Link] as plt
math_scores = [75, 85, 92, 60, 85, 95, 70, 80, 79, 91]
science_scores = [ 65, 70 ,85, 89, 90, 72, 76, 84,88, 92]
english_scores = [80, 85, 78, 82, 75, 90, 95, 87, 93]
data= [math_scores, science_scores, english_scores]
[Link](data)
[Link](" Box plot of Exam Scores by Subjects")
[Link]("Scores")
[Link]([1, 2, 3], ['Math', 'Science', 'English'])
[Link](True)
[Link]()
OUTPUT:
Scatter plot:
import [Link] as plt
height = [150, 160, 170, 180, 190]
weight = [50, 55, 60, 65, 70]
[Link](height, weight, color='blue', marker='o', s=100)
[Link]("Height vs Weight")
[Link]("Height (cm)")
[Link]("Weight (kg)")
[Link]()
OUTPUT:
Histogram:
import [Link] as plt
scores =[20, 45, 55, 60, 65, 30, 72, 75, 78, 50, 85, 88, 90, 35, 95,
98, 100]
[Link](scores, bins=8, color='green', edgecolor='black')
[Link]("Exam Score distribution.")
[Link]("Score Ranges")
[Link]("Number of students")
[Link]()
OUTPUT:
Program 20
Create Pair plot, Heatmap, and Distribution plot with
Seaborn.
Pair plot:
import seaborn as sns, pandas as pd, [Link] as plt
data = {
'Math': [78, 85, 92, 88, 76, 95, 89, 84, 90, 73],
'Science': [82, 79, 88, 91, 74, 96, 85, 87, 93, 70],
'English': [75, 80, 85, 82, 78, 88, 90, 86, 89, 77],
'Grade': ['A', 'A', 'A', 'A', 'B', 'A', 'A', 'A', 'A', 'B']
}
df = [Link](data)
[Link](df, hue='Grade', diag_kind='kde')
[Link]("Pair Plot of Student Scores", y=1.02)
[Link]()
OUTPUT:
Heatmap:
import seaborn as sns, pandas as pd, [Link] as plt
data = {
'Fruit': ['Mango', 'Banana', 'Guava', 'Papaya'],
'Maharashtra': [80, 30, 45, 35],
'Uttar Pradesh': [70, 25, 40, 30],
'Andhra Pradesh': [75, 28, 42, 33],
'Tamil Nadu': [85, 32, 47, 36],
'West Bengal': [65, 27, 39, 29] # (in ₹ per kg)
}
df = [Link](data)
df.set_index('Fruit', inplace=True)
[Link](figsize=(9, 5))
[Link](df, annot=True, cmap='coolwarm', fmt='d')
[Link]("Fruit Prices (₹/kg) Across Indian States")
[Link]("States")
[Link]("Fruits")
[Link]()
OUTPUT:
Distribution plot:
import seaborn as sns
import pandas as pd
import [Link] as plt
data = {
'student_id': range(1, 31),
'math_score': [55, 62, 78, 45, 89, 90, 76, 85, 67, 72,
91, 88, 77, 69, 96, 87, 64, 91, 88, 67,
81, 68, 79, 52, 60, 84, 66, 70, 75, 80]
}
df = [Link](data)
[Link](data=df, x='math_score', kde=True, bins=10,
color='mediumseagreen')
[Link](0, 100)
[Link]("Distribution of Math Exam Scores")
[Link]("Math Score")
[Link]("Number of Students")
[Link]()