Python Final Record
Python Final Record
AIM:
To write a program to demonstrate different number datatypes in python.
ALGORITHM:
Step 1: Start the program.
Step 2: Initialize and read the variables: i ,c ,f ,s ,b
Step 3: Print the values and types of each variable:
Print "the value of c is:", i, '\nits type is:', type(i)
Print "the value of c is:", f, '\nits type is:', type(f)
Print "the value of c is:", c, '\nits type is:', type(c)
Print "the value of c is:", s, '\nits type is:', type(s)
Print "the value of c is:", b, '\nits type is:', type(b)
Step 4: Stop the program.
CODING:
CLASS PERFORMANCE
RECORD
VIVA
TOTAL
RESULT:
Thus the program to demonstrate different number datatypes in python
was executed successfully.
2
EX.NO : 2 ARITHMETIC OPERATION
DATE:2.5.2023
AIM:
To write a program to perform different arithmetic operations on numbers
in python.
ALGORITHM:
Step 1: Start the program.
Step 2: Initialize variables a and b with values 10 and 3, respectively.
Step 3: Print "addition of a:{a} & b: {b} is: {a + b}"
Step 4: Print "subtraction of a: {a} & b: {b} is: {a - b}"
Step 5: Print "multiplication of a: {a} & b: {b} is: {a * b}"
Step 6: Print "division of a: {a} & b: {b} is: {a / b}"
Step 7: Print "floor division of a: {a} & b: {b} is: {a // b}"
Step 8: Print "modulus of a: {a} & b: {b} is: {a % b}"
Step 9: Stop the program.
CODING:
a=10; b=3
print("addition of a:",a,"&b:",b,"is:",a+b)
print("subtraction of a:",a,"&b:",b,"is:",a-b)
print("multiplication of a:",a,"&b:",b,"is:",a*b)
print("division of a:",a,"&b:",b,"is:",a/b)
print("floor division of a:",a,"&b:",b,"is:",a//b)
print("moduli of a:",a,"&b:",b,"is:",a%b)
print("exponent of a:",a,"&b:",b,"is:",a**b)
3
OUTPUT:
CLASS PERFORMANCE
RECORD
VIVA
TOTAL
RESULT:
4
EX.NO : 3 CONCATENATE A STRING
DATE:9.5.2023
AIM:
To Write a program to create, concatenate and print a string and
accessing sub- string from a given string.
ALGORITHM:
Step 1: Start the program.
Step 2: Initialize a pi with the value 3.14 and s and v with the value.
Step 3: Print "the value of s is: {s}","the value of v is: {v}".
Step 4: Concatenate the strings s and v.
Step 5: Print "after concatenating s and v the string is: {string_add}".
Step 6: Create a string "The value of pi is " followed by the string pi.
Step 7: Print the text string.
Step 8: Stop the program.
CODING:
pi=3.14
s= "Venkata" ;v= "Subhramanyam"
print("the value of s is:",s)
print("the value of v is:",v)
string_add = s+v
print("after concatenating s and v the string is:",s+v)
text = 'The value of pi is ' + str(pi)
print(text)
5
OUTPUT:
CLASS PERFORMANCE
RECORD
VIVA
TOTAL
RESULT:
Thus the program to create, concatenate and print a string and accessing
sub- string from a given string was executed successfully.
6
EX.NO : 4 PRINT THE TIME FORMAT
DATE: 16.5.2023
AIM:
To write a python script to print the current date in following format
“Sun May 29 02:26:23 IST 2017”
ALGORITHM:
CODING:
import time
import datetime
x =datetime.datetime.now()
print(x.strftime("%c"))
7
OUTPUT:
CLASS PERFORMANCE
RECORD
VIVA
TOTAL
RESULT:
Thus the python script to print the current date in following format “Sun
May 29 02:26:23 IST 2017” was executed successfully.
8
EX.NO : 5 APPEND AND REMOVE LIST
DATE: 24.5.2023
AIM:
To write a python program to create, append and remove lists in python.
ALGORITHM:
CODING:
9
OUTPUT:
CLASS PERFORMANCE
RECORD
VIVA
TOTAL
RESULT:
Thus the python program to create, append and remove lists in python
was executed successfully.
10
EX.NO : 6 WORKING WITH TUPLES
DATE: 26.5.2023
AIM:
To write a program to demonstrate working with tuples in python.
ALGORITHM:
CODING:
11
OUTPUT:
CLASS PERFORMANCE
RECORD
VIVA
TOTAL
RESULT:
12
EX.NO : 7 WORKING WITH DICTIONARY
DATE : 31.5.2023
AIM:
To write a program to demonstrate working with dictionaries in
python
ALGORITHM:
CODING:
13
print(college)
college["location"] = "IBP"
print(college)
college["location"] = "sheriguda"
print(college)
use pop()
college.pop("code")
print(college)
print("length of college is:",len(college))
mycollege= college.copy()
print(mycollege)
14
OUTPUT:
CLASS PERFORMANCE
RECORD
VIVA
TOTAL
RESULT:
15
EX.NO : 8 LARGEST OF THREE NUMBERS
DATE : 7.6.2023
AIM:
To write a python program to find largest of three numbers.
ALGORITHM:
Step 1: start the program
Step 2: Input three numbers: num1, num2, and num3.
Step 3: Compare the three numbers using statements (if, elif, else).
Step 4: Print the largest number. print("The largest number is:", largest).
Step 5: stop the program.
CODING:
larger def bigOf3(a,b,c):
if(a>b):
if(a>c):
print("a is greater than b and c")
else:
print("c is greater than a and b")
elif(b>c):
print("b is greater than a and c")
else:
print("c is greater than a and b")
txt= input("enter a,b,c values:")
a,b,c= txt.split()
bigOf3(int(a),int(b),int(c))
16
OUTPUT:
CLASS PERFORMANCE
RECORD
VIVA
TOTAL
RESULT:
Thus the python program to find largest of three numbers was executed
successfully.
17
EX.NO : 9 CONVERT CELSIUS TO FAHRENHEIT
DATE : 14.6.2023
AIM:
To write a python program to convert Celsius to Fahrenheit
ALGORITHM:
Step 1: start the program .
Step 2: Read the temperature in Celsius (C)
Step 3: Calculate Fahrenheit using : F = (C * 9/5) + 32 and display it.
Step 4: stop the program .
CODING:
while(1):
choice=input("ENTER YOUR CHOICE:")
ch=int(choice)
if(ch==1):
c=int(input("ENTER TEMPERATURE IN CELSIUS:"))
f=((9*c)/5)+32
print("converted temperature is:",f)
elif(ch==2):
f=int(input("ENTER TEMPERATURE IN FAHRENHEIT:"))
c=((f-32)/9)*5
print("converted temperature is:",c)
elif(ch==3):
exit()
else:
print("wrong choice")
18
OUTPUT:
CLASS PERFORMANCE
RECORD
VIVA
TOTAL
RESULT:
19
EX.NO : 10 PATTERN USING NESTED FOR LOOP
DATE : 21.6.2023
AIM:
To write a python program to construct the following pattern using
nested for loop.
ALGORITHM:
CODING:
n=int(input("ENTER A VALUE:"))
for x in range(0,n+1,1):
print(x*'*')
if(x==n):
for x in range(n,0,-1):
print(x*'*')
20
OUTPUT:
CLASS PERFORMANCE
RECORD
VIVA
TOTAL
RESULT:
Thus the python program to construct the following pattern using nested
for loop was executed successfully.
21
EX.NO : 11 PRINT THE PRIME NUMBERS LESS
AIM:
To write a python program to print prim numbers less than 20.
ALGORITHM:
CODING:
n=int(input("enter range of prime numbers:"))
for num in range(2,n+1):
count=0
for i in range(2,num//2+1):
if(num%i==0):
count=count+1
if(count==0):
print(num)
22
OUTPUT:
CLASS PERFORMANCE
RECORD
VIVA
TOTAL
RESULT:
Thus the python program to print prim numbers less than 20 was executed
successfully.
23
EX.NO : 12 FACTORIAL OF A NUMBER USING
DATE : 5.7.2023 RECURSION
AIM:
To write a python program to find factorial of a number using recursion
ALGORITHM:
STEP 1: Start the program.
STEP 2: Read the input number (n)
STEP 3: Define a function factorial(n)
STEP 3.1: If n is 0 or 1, return 1
STEP 3.2: Otherwise, return n times factorial of (n - 1)
STEP 4: Call the factorial function with n as input
STEP 5: Display the result
STEP 6: Stop the program.
CODING:
def recursion(n):
if(n<1):
print("FACTORIAL NOT POSSIBLE!!")
elif(n>1):
return n*recursion(n-1)
else:
return 1
n=int(input("enter a number:"))
print("factorial of",n,"is:",recursion(n))
24
OUTPUT:
CLASS PERFORMANCE
RECORD
VIVA
TOTAL
RESULT:
25
EX.NO : 13 RIGHT ANGLED TRIANGLE
DATE : 12.7.2023
AIM:
To write a python program indicate not the triangle is a right- angled
triangle
ALGORITHM:
Step 1: Start the program.
Step 2: Read the lengths of the three sides of the triangle (a, b, c)
Step 3: Sort the sides in ascending order: sides = [a, b, c]
Step 4: Calculate sum_of_short_sides = sides[0]^2 + sides[1]^2
Step 5: Calculate : longest_side_squared= sides[2]^2
Step 6: If sum_of_short_sides equals longest_side_squared, then
Step 6.1: Print "The triangle is a right-angled triangle."
Step 7: Else, Print "The triangle is not a right-angled triangle."
Step 8: Stop the program.
CODING:
a=float(input("enter length of hypotenuse side:"))
b=float(input("enter length of base side:"))
c=float(input("enter length of height side:"))
def pythagorean(a,b,c):
a=a*a; b=b*b; c=c*c
if(a==b+c):
print("yes!! the given inputs are triplets of a right angled triangle!!")
print("height:",c**0.5,"\nbase:",b**0.5,"\nhypotenuse:",a**0.5)
pythagorean(a,b,c)
26
OUTPUT:
CLASS PERFORMANCE
RECORD
VIVA
TOTAL
RESULT:
Thus the python the program should indicate whether or not the triangle
is a right- angled triangle was executed successfully.
27
EX.NO : 14 FIBONACCI SERIES
DATE : 19.7.2023
AIM:
To write a python program to define a module to find Fibonacci
Numbers and import the module to another program.
ALGORITHM:
CODING:
fibonacci.py
def fibonacci(n):
n1=0; n2=1;
print(n1)
print(n2)
for x in range(0,n):
n3=n1+n2
28
if(n3>=n):
break;
print(n3,end = ' ')
n1=n2
n2=n3
using_fibonacci.py
import fibonacci
n=int(input("enter range:"))
if(n<0):
print("enter correct range!!")
else:
print(" FIBONACCI SERIES \n")
fibonacci.fibonacci (n)
29
OUTPUT:
CLASS PERFORMANCE
RECORD
VIVA
TOTAL
RESULT:
Thus the python program to define a module to find Fibonacci
Numbers and import the module to another program was executed successfully.
30
EX.NO : 15 TO DEFINE A MODULE AND
DATE :26.7.2023 IMPORT A SPECIFIC FUNCTION
AIM:
To write a python program to define a module and import
a specific function in that module to another program.
ALGORITHM:
CODING:
def fibonacci(n):
n1=0; n2=1;
print(n1)
print(n2)
for x in range(0,n):
n3=n1+n2
if(n3>=n):
break;
print(n3,end = ' ')
31
n1=n2
n2=n3
n=int(input("enter range:"))
if(n<0):
print("enter correct range!!")
else:
print(" FIBONACCI SERIES \n")
fibonacci (n)
32
OUTPUT:
5
21
CLASS PERFORMANCE
RECORD
VIVA
TOTAL
RESULT:
33
EX.NO : 16 COPY FILE
DATE :28.7.2023
AIM:
To write a script named copyfile.py. . The contents of the first
file should be input and written to the second file.
ALGORITHM:
CODING:
34
OUTPUT:
CLASS PERFORMANCE
RECORD
VIVA
TOTAL
RESULT:
35
EX.NO: 17 TO PRINT ALL OF THE UNIQUE
DATE: 2.8.2023 WORDS
AIM:
To write a program that inputs a text file. The program should print all of
the unique words in the file in alphabetical order
ALGORITHM:
CODING:
36
word=line.rstrip().split()
for element in word:
if element in our_list:
continue
else:
our_list.append(element)
our_list.sort()
print(our_list)
37
OUTPUT:
CLASS PERFORMANCE
RECORD
VIVA
TOTAL
RESULT:
Thus the program that inputs a text file. The program should print
all of the unique words in the file in alphabetical order was executed
successfully.
38
EX.NO : 18 CONVERT AN INTEGER TO A
DATE : 4.8.2023 ROMAN NUMERAL
AIM:
To write a Python class to convert an integer to a roman numeral.
ALGORITHM:
39
CODING:
class roman_solution:
def int_to_Roman(num):
val = [1000, 900, 500, 400, 100, 90, 50, 40, 9, 5, 4, 1]
syb = ["M", "CM", "D", "CD", "C", "XC", "L", "XL","X", "IX", "V", "IV",
"I” ]
roman_num = “”
i=0
if(n<1 or n>3999):
print("ENTER A GOOD VALUE!")
else:
while num > 0:
if(num-val[i]>=0):
roman_num+=syb[i]
num-=val[i]
else:
i+=1
return roman_num
n=int(input("ENTER A NUMBER:"))
print("roman numeral of given number is:",roman_solution.int_to_Roman(n))
40
OUTPUT:
CLASS PERFORMANCE
RECORD
VIVA
TOTAL
RESULT:
41
EX.NO : 19 TO IMPLEMENT POW(x,n)
DATE : 9.8.2023
AIM:
To write a Python class to implement pow(x, n)
ALGORITHM:
Step1: Start the program.
Step2: Define a class named py_power and define a method named
power(x, n):
Step2.1: Print the values of x and n.
Step 2.2: Calculate the result of raising x the power n using the operator
**.
Step 2.3: Print the calculated result.
Step 3: Prompt the user to input the x (base) value as a floating-point
number.
Step 3.1: Prompt the user to input the n (power) value floating-point
number.
Step 4: Create an instance of the py_power class.
Step 4.1: Call the power() method of the instance, passing the input
values for x and n
Step 5:Stop the program.
CODING:
class py_power:
def power(x,n):
print("power of given literals:\nx:",x,"\nn\n:",n,"is:",x**n)
x=float(input("ENTER X(BASE) VALUE:"))
n=float(input("ENTER N(POWER) VALUE:"))
py_power.power(x,n)
42
OUTPUT:
CLASS PERFORMANCE
RECORD
VIVA
TOTAL
RESULT:
43
EX.NO : 20 REVERSE A STRING WORD
DATE : 11.8.2023 BY WORD
AIM:
To write a Python class to reverse a string word by word.
ALGORITHM:
Step 1: Start the program.
Step 2: Initialize the f name variable with a sentence.
Step 3: Split the sentence into words using the split () method.
Step 4: Iterate each element in the word list: Append the element to the
our list
Step 5: Print the original sentence list: "tried sentence is:" followed by
our_list.
Step 6: Reverse the elements in our_list using the reverse() method.
Step 7: Print list after reversal: "list after the reverse()" by the our_list.
Step 8: Stop the program.
CODING:
fname="HELLO EVERYONE THIS IS PYTHON PROGRAMMING AND
WE'RE PLAYING WITH LISTS"
our_list=list()
word=fname.split()
for element in word:
our_list.append(element)
print("tried sentence is:",our_list)
our_list.reverse()
print("list after the reverse()",our_list)
44
OUTPUT:
tried sentence is: ['HELLO']
tried sentence is: ['HELLO', 'EVERYONE']
tried sentence is: ['HELLO', 'EVERYONE', 'THIS']
tried sentence is: ['HELLO', 'EVERYONE', 'THIS', 'IS']
tried sentence is: ['HELLO', 'EVERYONE', 'THIS', 'IS', 'PYTHON']
tried sentence is: ['HELLO', 'EVERYONE', 'THIS', 'IS', 'PYTHON',
'PROGRAMMING']
tried sentence is: ['HELLO', 'EVERYONE', 'THIS', 'IS', 'PYTHON',
'PROGRAMMING', 'AND']
tried sentence is: ['HELLO', 'EVERYONE', 'THIS', 'IS', 'PYTHON',
'PROGRAMMING', 'AND', "WE'RE"]
tried sentence is: ['HELLO', 'EVERYONE', 'THIS', 'IS', 'PYTHON',
'PROGRAMMING', 'AND', "WE'RE", 'PLAYING']
tried sentence is: ['HELLO', 'EVERYONE', 'THIS', 'IS', 'PYTHON',
'PROGRAMMING', 'AND', "WE'RE", 'PLAYING', 'WITH']
tried sentence is: ['HELLO', 'EVERYONE', 'THIS', 'IS', 'PYTHON',
'PROGRAMMING', 'AND', "WE'RE", 'PLAYING', 'WITH', 'LISTS']
list after the reverse() ['LISTS', 'WITH', 'PLAYING', "WE'RE", 'AND',
'PROGRAMMING', 'PYTHON', 'IS', 'THIS', 'EVERYONE', 'HELLO']
CLASS PERFORMANCE
RECORD
VIVA
TOTAL
RESULT:
Thus the Python class to reverse a string word by word was executed
successfully.
45