practicalXII2025gdgawefe

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

PRACTICAL-1

Aim: To find out compound interest on given principle, rate and time
using function
Date: 03-05-2024
Developed By: your name
Mentor: Pradumna Singh Sir

def compint(p,r,t):
ci=(p*(1+(r/100))**t)-p
return ci
#main program
p=float(input('Enter principle:--'))
r=float(input('Enter rate:--'))
t=float(input('Enter time:--'))
CI=compint(p,r,t)
print('Compound Interest is ',CI)

SAMPLE OUTPUT 1:
Enter principle:--1000
Enter rate:--10
Enter time:--1
Compound Interest is 100.0

SAMPLE OUTPUT 2:
Enter principle:--1000
Enter rate:--10
Enter time:--2
Compound Interest is 210.00000000000023

PRACTICAL-2
Aim: WAF to check whether the given number is an Armstrong number
or not.
Date: 06-05-2024
Developed By: your name
Mentor: Pradumna Singh Sir

#program to check Armstrong number


def arm(n):
sum=0
while n!=0:
rem=n%10
sum+=rem**3
n//=10
return sum
#main code
num=int(input('Enter any integer:--'))
s=arm(num)
if s==num:
print(num,' is an armstrong number')
else:
print(num,' is not an armstrong number')

SAMPLE OUTPUT 1:
Enter any integer:--153
153 is an armstrong number

SAMPLE OUTPUT 2:
Enter any integer:--657
657 is not an armstrong number

PRACTICAL-3

Aim: Write a function REP which accepts a list of integers and its size as
arguments and replaces elements having even values with its half and
elements having odd values with twice its value.
Eg: if the list contains 3, 4, 5, 16, 9 then the function should rearranged
list as 6, 2,10,8, 18
Date: 08-05-2024
Developed By: your name
Mentor: Pradumna Singh Sir
def REP(L,S):
for i in range(S):
if L[i]%2==0:
L[i]=L[i]//2
else:
L[i]=L[i]*2
return L

#main program
l=[]
n=int(input('Enter size of list:--'))
print('Enter ',n,' numbers:--')
for i in range(n):
l.append(int(input()))
print('Original list is:',l)
L=REP(l,n)
print('Resultant list is:',L)

Sample Output: (to be written on left size on plain page)


Enter size of list:--5
Enter 5 numbers:--
2
4
6
7
99
Original list is: [2, 4, 6, 7, 99]
Resultant list is: [1, 2, 3, 14, 198]

PRACTICAL-4
Aim: To write a function that receives tuple as its argument containing N
integers. Find out the greatest and smallest number present in tuple.
Invoke the function in main program.
Date: 10-05-2024
Developed By: your name
Mentor: Pradumna Singh Sir

#A function to find out the smallest and greatest number in tuple


def GSM(t,n):
sm=gr=t[0]
for i in range(1,n):
if t[i]>gr:
gr=t[i]
if t[i]<sm:
sm=t[i]
return sm,gr
#main program
t=()
N=int(input('Enter size of tuple:--'))
print('Enter ',N,' numbers:--')
for i in range(N):
a=float(input())
t+=(a,)
print('Data in tuple are:-')
for i in t:
print(i,end=' ')
S,G=GSM(t,N)
print('\nGreatest Number: ',G)
print('\nSmallest Number: ',S)

OUTPUT:
Enter size of tuple:--6
Enter 6 numbers:--
56
23
90
56
34
96
Data in tuple are:-
56.0 23.0 90.0 56.0 34.0 96.0
Greatest Number: 96.0
Smallest Number: 23.0
PRACTICAL-5
Aim: Write a function in Python to count and assign the frequency of
words in the given string using a dictionary.
Date: 13-05-2024
Developed By: your name
Mentor: Pradumna Singh Sir

def frequency(S):
words=S.split()
d={}
for i in words:
key=i
if key not in d:
c=words.count(key)
d[key]=c
for i in d:
print(i,'--',d[i])
#main program
S=input("Enter any string:--")
frequency(S)

SAMPLE OUTPUT:
Enter any string:--i love my country i love my mom too
i -- 2
love -- 2
my -- 2
country -- 1
mom -- 1
too -- 1

You might also like