Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 32

LAB RECORD

NAME : G Madhan Balaji


ROLL NO. : CB.EN.U4ARE20128
COURSE NAME : Python Programming
COURSE CODE : 19CSE282

LAB EVALUATION 0

1.
AIM:
To find the simple interest using python code and formula.
ALGORTHIM:
i) Define a function with 3 parameters.
ii) Assign a variable to calculate the simple interest using formula.
iii) Input the values for variables (principle, rate of interest and time
period).
iv) Call the function with the above input values as parameters.
PROGRAM:
def intr(P,R,T):
SI=(P*T*R)/100
print(SI)
pr=float(input("Enter principle amt:"))
ra=float(input("Enter rate of interest:"))
ti=float(input("Enter time period:"))
intr(pr,ra,ti)
OUTPUT:

INFERENCE:
The simple interest was found using python and formula.

2.
AIM:
To find the gain percentage using python code.
ALGORTHIM:
i) Define a function with 3 parameters.
ii) The gain percentage is calculated.
iii) Input the values for variables (Price for which it was bought, cost of
service, and for much it was sold).
iv) Call the function with the above input values as parameters.
PROGRAM:
def gain(A,B,C):
gain=((C-(A+B))/(A+B))*100
print("The gain percentage",gain,"%")
a=float(input("Enter the price for which it was bought:"))
b=float(input("Enter the service amt:"))
c=float(input("Enter the price for which it was sold:"))
gain(a,b,c)
OUTPUT:

INFERENCE:
The gain percentage was founded using python.

3.
AIM:
To find the perimeter of the rectangle using python.
ALGORTHIM:
i) Define a function with 2 parameters.
ii) Perimeter is found using the formula.
iii) Input the length and breadth.
iv) The function is called with the above input length and breadth.
PROGRAM:
def peri(L,B):
per=2*(L+B)
print("The perimeter is:",per)
l=int(input("Enter the length:"))
b=int(input("Enter the breadth:"))
peri(l,b)
OUTPUT:

INFERENCE:
The perimeter was found out using python.

4.
AIM:
To compute the smallest number of notes that will combine to give
Rs. 200 using python.
ALGORTHIM:
i) A function is defined.
ii) Then the amount is inputted.
iii) Then conditions are checked one by one for each denomination.
iv) Then the least way is printed.
PROGRAM:
def change():
One=0
Two=0
Five=0
Ten=0
Fifty=0
Hundred=0
N=int(input("Enter the input:"))
Hundred=N//100
N=N%100
Fifty=N//50
N=N%50
Ten=N//10
N=N%10

Five=N//5
N=N%5

Two=N//2
N=N%2

One = N

Sum=One+Two+Five+Ten+Fifty+Hundred
print(Sum)
change()
OUTPUT:

INFERENCE:
The least number of notes was found out using python.
LAB EVALUATION 1
PART-A
1.
AIM:
To convert Celsius to Fahrenheit and vice-versa using python.
ALGORTHIM:
i) Define a function with temperature as parameter.
ii) Then the user is asked for the conversion is it from Celsius to
Fahrenheit or Fahrenheit to Celsius.
iii) After this the conversion is done using the formula.
iv) Finally the function is called with the temperature as the parameter.
PROGRAM:
def convert(t):
if a==1:
f=1.8*t+32
print("The temp in Fahrenheit is:",f)
elif a==2:
c=(t-32)/1.8
print("The temp in Celsius is:",c)
else:
print("Sorry!!!")
print('''1 for Celsius to Fahrenheit
2 for Fahrenheit to Celsius''')
a=int(input("Enter ur choice"))
b=float(input("Enter the temp:"))
convert(b)
OUTPUT:

INFERENCE:
The conversion was done with the help of python.

2.
AIM:
To find the roots of a quadratic equation.
ALGORTHIM:
i) Module math is imported
ii) A function is defined.
iii) The determinant is found out and with the help of this the root with the
help of math.sqrt() i.e., math module’s square root option.
iv) Then the value of the coefficient of x2,x and the value of constant term in
a quadratic equation.
v)The function is called the above inputted values.
PROGRAM:
import math
def root(a,b,c):
i=b**2-4*a*c
d=math.sqrt(i)
x1=(-b+d)/2*a
x2=(-b-d)/2*a
print("Root 1:",x1)
print("Root 2:",x2)
e=int(input("Enter a no.:"))
f=int(input("Enter a no.:"))
g=int(input("Enter a no.:"))
root(e,f,g)
OUTPUT:

INFERENCE:
The roots of the quadratic equation with the help of python
PART-B
1.
AIM:
To find the area of circle by getting the radius as input with the help
of python.
ALGORTHIM:
i) First, we import math module.
ii) A function is defined.
iii) We get the radius of the circle as a input.
iv) Then the area if found out with the formula and with the help of the pi
module from math module i.e., math.pi().
v) Then the function is called by having radius as the parameter.
PROGRAM:
import math
def area(r):
if r<0:
print("Radius less than 0!!")
elif(r==0):
print("0")
else:
a=math.pi*(r**2)
print(a)
b=int(input("Enter r:"))
area(b)
OUTPUT:

INFERENCE:
The area of the circle was found out by using python.

2.
AIM:
To find value of n+nn+nnn using python.
ALGORTHIM:
i) A function is defined.
ii) Then the value of n+nn+nnn is assigned to a variable.
iii) And then the variable is printed.
iv) The function is called after getting value of n.
PROGRAM:
def comp(n):
a=n+n*n+n*n*n
print(a)
b=int(input("Enter:"))
comp(b)
OUTPUT:

INFERENCE:
The value of n+nn+nnn is calculated with the help python

3.
AIM:
To print a calendar for a given year and month with help of calendar
function in python
ALGORTHIM:
i) Calendar module is imported.
ii) A function is created.
iii) Year and month are got from the user as an input.
iv) The calendar is print.
v) The function is called.
PROGRAM:
def calen(m):

a={"January":31,"February":28,"March":31,"April":30,"May":31,"June":3
0,"July":31,"August":31,"September":30,"October":31,"November":30,"D
ecember":31}
if type(a)==str:
print("Enter only the number of the month")
elif m<=0:
print("No negative numbers or zero")
else:
c=int(input("Enter the year:"))
d=list(a)
if m==2 and c%4==0:
print("No.of days: 29")
else:
if m>12:
print("Enter a number b/w 1 and 12")
else:
f=d[m-1]
g=a[f]
print("No. of days:",g)
print('''List of months:
1. January
2. February
3. March
4. April
5. May
6. June
7. July
8. August
9. September
10. October
11. November
12. December
''')
b=int(input("Enter the number of month:"))
calen(b)
OUTPUT:
INFERENCE:
The calendar is printed with the calendar function using python

4.
AIM:
To find the area of triangle with the help of base and height as an
input in python.
ALGORTHIM:
i) A function is defined by having base and height as parameters.
ii) The area is calculated with the formula.
iii) The height and base length are got as an input from the user.
iv) Then the function is called with the inputted values of base and height.
PROGRAM:
def areat(b,h):
a=(b*h)/2
print(a)
c=int(input("Enter height:"))
d=int(input("Enter base:"))
areat(c,d)
OUTPUT:

INFERENCE:
The area of triangle is calculated with the help of python by getting
base and height as input

LAB EVALUATION 2

1.
AIM:
To find the sum of squares of a given number with the help of
python.
ALGORTHIM:
i) Define a function having a variable as a parameter.
ii) Then we loop it in a range function.
iii) Then the squared term is added and printed finally.
iv) The number is got as an input from the user
v) The function is called with the inputted value
PROGRAM:
def sq(a):
c=0
d=0
for i in range(1,a+1):
c=i**2
d+=c
print("Sum of squares",d)
n=int(input("Enter the value of n:"))
sq(n)
OUTPUT:

INFERENCE:
The sum of squares of a given number is found out with the help of
python.

2.
AIM:
To find out whether the given number is prime or not with the help
of python.
ALGORTHIM:
i) Define a function.
ii) Then use loops to check the conditions to check the prime number.
iii) Then we get the number as an input.
iv) Function is called with the above value.
PROGRAM:
def prime(num):
if num > 1:
for i in range(2, int(num/2)+1):
if (num % i) == 0:
print(num, "is not a prime number")
break
else:
print(num, "is a prime number")
elif(num==1):
print(num, "is nethier prime number nor a composite number")
else:
print(num, "is not a prime number")
a=int(input("Enter"))
prime(a)
OUTPUT:

INFERENCE:
The given is prime or not is being checked using python.

3.
AIM:
To find the sum and factorial of a given number using python.
ALGORTHIM:
i) Define a function to find the sum and factorial of the input number
which is given as the parameter.
ii) Then using to loops the sum and factorial of the given number is found.
iii) The number is got as an input from the user.
iv) Then the function is called with that value.
PROGRAM:
def snf(n):
sum = 0
fact=1
for num in range(1, n + 1, 1):
sum = sum + num
for num1 in range(1, n + 1, 1):
fact = fact * num1
print("Sum of first ", n, "numbers is: ", sum)
print("Factorial of ", n, "numbers is: ", fact)
m = int(input("Enter number"))
snf(m)
OUTPUT:

INFERENCE:
The sum and factorial of the given number is found out using
python.

4.
AIM:
To find the value of Ramanujan number that any set of quadruples
can generate(a,b,c,d) where 0<a,b,c,d<L
Ramanujan number (N)=a3+b3=c3+d3
Write a python program to do this.
ALGORTHIM:
i) First import math module to perform this activity easily.
ii) Define a function to perform this activity.
iii) Then using cube of all 3 numbers it is equated and checked.
iv) If the condition passes it is Ramanujan number.
v) The value of a,b,c,d is got as an input.
vi) The function is called by the value given by the user.
PROGRAM:
import math
def raman(N):
i, count = 1, 0
while (count < N):

int_count = 0
for j in range(1, math.ceil(\
pow(i, 1.0 / 3)) + 1):
for k in range(j + 1,\
math.ceil(pow(i, 1.0 / 3)) + 1):
if (j * j * j + k * k * k == i):
int_count += 1
if (int_count == 2):

count += 1
print(count, " ", i)

i += 1
a = int(input("Enter:"))
raman(a)
OUTPUT:

INFERENCE:
The Ramanujan number is found out using python.

5.
AIM:
To find cube root of a perfect cube using python.
ALGORTHIM:
i) Define a function for finding the perfect cube root.
ii) Then we check how whether the given number is a perfect cube or not.
iii) Then we find the cube root of the given number.
iv) Then we get the number to checked from the user as an input.
v) Then the function is called the by the given value.
PROGRAM:
def cube(a):
c=a**(1/3)
if int(c%3)==0:
print(a,"Is a cube root")
else:
print(a,"Is not a cube root")
b=int(input("Enter:"))
cube(b)
OUTPUT:

INFERENCE:
The cube root of a perfect cube is found out using python.

LAB EVALUATION 3
1.
AIM:
To write a python program to find whether the given input string is a
palindrome or not.
ALGORTHIM:
i) Define a function to reuse it.
ii) Firstly, we reverse the given word.
iii) Then we check it out with the original string to check the condition for
palindrome.
iv) To check this, we get an input string from the user and check it.
v) At last, we call the function with the given string.
PROGRAM:
def palin(a):
b=a[::-1]
if b==a:
print("True")
else:
print("False")
c=input("Enter:")
palin(c)
OUTPUT:

INFERENCE:
A program was written to find out whether is it a palindrome or not.
2.
AIM:
To find a factorial of a number using python.
ALGORTHIM:
i) Define a function.
ii) Then we check the conditions to find the factorial.
iii) For 1 it is 1 only.
iv) Then we get the number from the user.
v) Then we call the function.
PROGRAM:
def fact(n):
if n==0:
print("1")
o=1
if n>=1:
for i in range(1,n+1):
o*=i
print(o)
else:
print("Sorry enter +ve no.")
b=int(input("enter:"))
fact(b)
OUTPUT:
INFERENCE:
Factorial was found out using python.

3.
AIM:
To convert Celsius to Fahrenheit and vice-versa by using functions
using python.
ALGORTHIM:
i) Define a function with temperature as parameter.
ii) Then the user is asked for the conversion is it from Celsius to
Fahrenheit or Fahrenheit to Celsius.
iii) After this the conversion is done using the formula.
iv) Finally, the function is called with the temperature as the parameter.
PROGRAM:
def conversion1(Celsius_inp):
c=Celsius_inp
b=(c*(9/5))+32
print("The temp in farenheit is:",b)
def conversion2(Fahrenheit_inp):
f=Fahrenheit_inp
d=(f-32)*(5/9)
print("The temp in celcius is:",d)
print("""1. For celcius to farenheit
2. For farenheit to celcius """)
a=int(input("Enter ur input:"))
if a==1:
Celsius=float(input("Enter degree in celcius:"))
conversion1(Celsius)
elif a==2:
Fahrenheit=float(input("Enter degree in fahrenheit:"))
conversion2(Fahrenheit)
else:
print("Wrong input!!")
OUTPUT:

INFERENCE:
Temperature was converted using functions in python

4.
AIM:
To write a Python program to get a string made of the first 3 and the
last 3 chars from a given a string. If the string length is less than 3, return
instead of the empty string.
ALGORTHIM:
i) Define a function.
ii) Then the length of the input string is checked.
iii) If the length is more than 6 the first and last 3 characters are added in
single string and printed.
iv) If the length is less than 6 then it will return an empty string.
v) Then the string is got as an input from the user.
vi) Finally, the function is called with the string as a parameter
PROGRAM:
def sep(a):
if len(a)>6:
b=a[0:3]
c=a[-3:]
d=b+c
print(d)
else:
print("Sorry")
d=input("Enter:")
sep(d)
OUTPUT:
INFERENCE:
The program to get a string made of the first 3 and the last 3 chars
from a given a string is made using python.

5.
AIM:
Write a Python program to add 'ing' at the end of a given string
(length should be at least 3). If the given string already ends with 'ing' then
add 'ly' instead. If the string length of the given string is less than 3, leave
it unchanged
ALGORTHIM:
i) Define a function.
ii) Then the length of the input string is checked.
iii) With the length we decide what to do like and ‘ing’ if it is not ending
with ‘ing’. Else adding ‘ly’.
iv) Then the string is got as an input from the user.
v) Finally, the function is called with the string as a parameter.
PROGRAM:
def add(b):
if b[-3:]=="ing":
b+="ly"
elif (len(b)<3):
pass
else:
b+="ing"
print(b)
a=input("Enter:")
add(a)
OUTPUT:

INFERENCE:
The program to add 'ing' at the end of a given string (length should
be at least 3). If the given string already ends with 'ing' then add 'ly' instead
was done with the help of python

LAB EVALUATION 4
1.
AIM:
Write a Python program to get the smallest number, largest number,
sum, and average from a list and remove duplicates.
ALGORTHIM:
i) A function is created and all the things to be done are put in it.
ii) For each and everything a separate variable is created.
iii) To find the things we have used the following:
a) min()- To find the minimum value.
b) max()- To find the maximum value.
c) len()- To find the length of the list.
d) sum()- To find the sum of digits inside a list
e) count()- To count the number of times the item is present inside
the list.
f) remove()- To remove an item from the list, here it is used to
remove the duplicate items present in the list.
iv) Then we print the values got it.
v) We get list as an input from the user.
vi) Then we call the function using the list as a parameter.
PROGRAM:
def func(a):
b=min(a)
c=max(a)
d=sum(a)
e=len(a)
f=d/e
g=0
print("The minimum value is:",b)
print("The maximum value is:",c)
print("The sum is:",d)
print("The average is:",f)
for i in a:
g=a.count(i)
if g>1:
a.remove(i)
print("The list after removing duplicate items",a)
l=list(eval(input("Enter:")))
func(l)
OUTPUT:

INFERENCE:
The program to find out minimum, maximum, sum, average and
remove duplicate items is written using python.

2.
AIM:
Write a Python program to find the summation of digits of numbers
in the List.
ALGORTHIM:
i)
ii)
iii)
iv)
v)
PROGRAM:
OUTPUT:
INFERENCE:

3.
AIM:
ALGORTHIM:
i)
ii)
iii)
iv)
v)
PROGRAM:
OUTPUT:
INFERENCE:

4.
AIM:
ALGORTHIM:
i)
ii)
iii)
iv)
v)
PROGRAM:
OUTPUT:
INFERENCE:
5.
AIM:
ALGORTHIM:
i)
ii)
iii)
iv)
v)
PROGRAM:
OUTPUT:
INFERENCE:

You might also like