Python Programs 19.02.2025
Python Programs 19.02.2025
Algorithm:
Step 1: Start
Step 2: Define all the operations with variables and use conditional statements
Step 2: Use print function to obtain the output
Step 3: Execute the output
Step 4: Stop
Source code:
def add(a,d):
return a+b
def sub(c,d):
return c-d
def mul(b,h):
return b*h
def div(g,h):
return g/h
print("=================")
print("1.TO PERFORM ADDITION")
print("2.TO PERFORM SUBTRACTION")
print("3.TO PERFORM MULTIPLICATION")
print("4.TO PERFORM DIVISION")
print("=================")
choice = int(input("Enter Your choice"))
if choice ==1:
a=int(input("Enter the 1st value"))
b=int(input("Enter the 2nd value"))
print(add(a,b))
elif choice ==2:
c=int(input("Enter the 1st value"))
d=int(input("Enter the 2nd value"))
print(sub(c,d))
elif choice ==3:
e=int(input("Enter the 1st value"))
f=int(input("Enter the 2nd value"))
print (mul(e,f))
elif choice ==4:
g=int(input("Enter the 1st value"))
h=int(input("Enter the 2nd value"))
print(areadOfSquare(S))
else:
print("Wrong choice")
Output:
=================
1.TO PERFORM ADDITION
2.TO PERFORM SUBTRACTION
3.TO PERFORM MULTIPLICATION
4.TO PERFORM DIVISION
=================
Enter Your choice 12
Wrong choice
Result:
The output is executed successfully
Ex no- 9.B. write a python program to concatenate the data
frames with two different objects.
Aim: To write a python program to concatenate the data frames with two
different objects.
Algorithm:
Step 1: Start
Step 2: Import pandas to create a data frame
Step 3: Assign the data sets to concatenate and obtain data frame as output
Step 4: Execute the output
Step 5: Stop
Source code:
import pandas as pd
Output
Name Age
0 Alice 25
1 Bob 30
2 Charlie 35
3 David 40
4 Eve 45
5 Frank 50
Result:
The output is executed successfully
Ex No-9. C. Write a Python script to sort (ascending and
descending) a dictionary by value using the item function
Algorithm:
Step 1: Star
Step 2: Create a dictionary with appropriate elements
Step 3: Sort the dictionary with key values
Step 4: Execute the output
Step 5: Stop
Source Code :
my_dict={'c':3,'a':1,'d':4,'b':2}
sorted_dict=sorted([(value,key)for(key,value)in my_di
ct.items()])
print("Sorted dictionary is :")
print(sorted_dict)
Output:
Sorted dictionary is :
[(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd')]
Result:
The output is executed successfully