SlideShare a Scribd company logo
1 of 31
Download to read offline
PYTHON LAB
1
PYTHON LAB
2
Table of Contents
FIND THE LARGEST AMONG THREE NUMBERS .................................................................................... 3
FIND MEAN,MEDIAN,MODE FROM GIVEN NUMBER............................................................................ 4
SWAP TWO VARIABLES......................................................................................................................... 5
CHECK ARMSTRONG NUMBER.............................................................................................................. 6
TO FIND THE SQUAR ROOT ................................................................................................................... 7
TO CHECK IF A NUMBER IS ODD OR EVEN ............................................................................................ 8
REVERSE A NUMBER............................................................................................................................. 9
TO CHECK PALINDROME..................................................................................................................... 10
TO CHECK LEAP YEAR.......................................................................................................................... 11
FIND THE AREA OF TRIANGLE ............................................................................................................. 12
NUMBER OF CHARACTER IN THE STRING AND STORE THEM IN A DICTIONARY DATA STRUCTURE.... 13
FIND THE PRIME NUMBER.................................................................................................................. 14
TO FIND LENGTH OF A STRING............................................................................................................ 15
TO FIND THE ADDITION, SUBTRACTION, MULTIPICATION,DIVISION .................................................. 16
FIND THE VALUE OF CHARACTER........................................................................................................ 19
THE DISPLAY CALENDAR ..................................................................................................................... 20
COMPUTE THE POWER OF A NUMBER ............................................................................................... 21
TO CHECK IF A NUMBER IS POSITIVE, NEGATIVE, OR ZERO ................................................................ 22
DISPLAY THE MULTIPLICATION TABLE.............................................................................................. 23
FIND ALL DUPLICATES IN THE LIST ...................................................................................................... 24
Find the factorial of a number ............................................................................................................ 25
ADD TWO MATRICES .......................................................................................................................... 26
COUNT THE NUMBER OF DIGITSPRESENT IN A NUMBER ................................................................... 27
FIND ALL THE UNIQUE ELEMENTS OF A LIST....................................................................................... 28
CONVERT DECIMAL TO BINARY,OCTAL AND HEXADECIMAL............................................................... 29
CONVERT CELSIUS TO FAHRENHEIT.................................................................................................... 30
CONVERT KILOMETERS TO MILES ....................................................................................................... 31
PYTHON LAB
3
EX:NO:1
FIND THE LARGEST AMONG THREE NUMBERS
DATE:
SOURCE CODE:
a = int(input("A:"))
b = int(input("B:"))
c = int(input("C:"))
if(a > b and a > b):
print("Largest : ",a)
elif(b > a and b > c):
print("Largest : ",b)
elif(c > a and c > b):
print("Largest : ",c)
OUTPUT:
A:36
B:82
C:91
Largest : 91
PYTHON LAB
4
EX:NO:2
FIND MEAN,MEDIAN,MODE FROM GIVEN NUMBER
DATE:
SOURCE CODE:
print("FIND MEAN,MEDIAN,MODE")
print("**********************")
from statistics import mean, median, mode
l = [ 36, 56, 76, 82, 27]
print("MEAN:",mean(l))
print("MEDIAN:",median(l))
print("MODE:",mode(l))
print("**********************")
OUTPUT:
FIND MEAN,MEDIAN,MODE
**********************
MEAN: 55.4
MEDIAN: 56
MODE: 36
PYTHON LAB
5
EX:NO:3
SWAP TWO VARIABLES
DATE:
SORCE CODE:
print("SWAP THE VARIABLES")
print("*******************")
a = 6
b = 3
temp = a
a = b
b = temp
print("The Value of a After Swapping:",format(a))
print("The Value of a After Swapping:",format(b))
OUTPUT:
SWAP THE VARIABLES
*******************
The Value of a After Swapping: 3
The Value of a After Swapping: 6
PYTHON LAB
6
EX:NO:4
CHECK ARMSTRONG NUMBER
DATE:
SOURCE CODE:
print("CHECK ARMSTRONG NUMBER")
print("_______________________")
num = int(input("Enter the number:"))
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
if num == sum:
print(num,"Is An Amstrong...")
else:
print(num,"Is An Amstrong...")
OUTPUT:
CHECK ARMSTRONG NUMBER
_______________________
Enter the number:356
356 Is An Amstrong...
PYTHON LAB
7
EX:NO:5
TO FIND THE SQUAR ROOT
DATE:
SOURE CODE:
print(" The Square Root")
print("~~~~~~~~~~~~~~~~~")
import cmath
n = int(input("N:"))
result = cmath.sqrt(n)
print("Square root of",n,"is",result)
OUTPUT:
The Square Root
~~~~~~~~~~~~~~~~
N :6
Square root of 6 is (2.449489742783178+0j)
PYTHON LAB
8
EX:NO:6
TO CHECK IF A NUMBER IS ODD OR EVEN
DATE:
SOURCE CODE:
print("ODD ARE EVEN NUMBER")
print("___________________")
num = int(input("Enter the number :"))
if( num % 2) == 0:
print(" {0} is even". format(num))
else:
print(" {0} is odd". format(num))
OUTPUT:
ODD ARE EVEN NUMBER
___________________
Enter the number :36
36 is even
PYTHON LAB
9
EX:NO:7
REVERSE A NUMBER
DATE:
SOURCE CODE:
print("REVERSE A NUMBER")
print("*****************")
num = int(input("Enter the number:"))
reversed_num = 0
while num != 0:
digit = num % 10
reversed_num = reversed_num * 10 + digit
num //= 10
print("Reverse the number :" +str(reversed_num))
OUTPUT:
REVERSE A NUMBER
*****************
Enter the number:987654321
Reverse the number :123456789
PYTHON LAB
10
EX:NO:8
TO CHECK PALINDROME
DATE:
SOURCE CODE:
print("TO CHECK PALINDROME")
print("*******************")
s = str(input("ENTER THE STRING:"))
def ispalindrome(s):
return s == s [ : :-1]
ans = ispalindrome(s)
if ans:
print(s,"is a palindrom")
else:
print(s,"is a palindrom")
OUTPUT:
TO CHECK PALINDROME
*******************
ENTER THE STRING:AMMA
AMMA is a palindrom
PYTHON LAB
11
EX:NO:9
TO CHECK LEAP YEAR
DATE:
SOURCE CODE:
print("CHECK LEAP YEAR")
print("*****************")
year = int(input("ENTER THE YEAR :"))
if (year % 4) == 0:
if (year % 100) == 0:
if(year % 400) == 0:
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))
else:
print("{0} is a leap year".format(year))
else:
print("{0} is a not a leap year".format(year))
OUTPUT:
CHECK LEAP YEAR
*****************
ENTER THE YEAR :2022
2022 is a not a leap year
PYTHON LAB
12
EX:NO:10
FIND THE AREA OF TRIANGLE
DATE:
SOURCE CODE:
print("AREA OF TRIANGLE")
print("*****************")
a = int(input("Enter the Value of A:"))
b = int(input("Enter the Value of B:"))
c = int(input("Enter the Value of C:"))
s = (a + b + c)/2
area = (s*(s-a)*(s-b)*(s-c)**0.5)
print("The Area of the Triangle is:",area)
OUTPUT:
AREA OF TRIANGLE
*****************
Enter the Value of A:6
Enter the Value of B:5
Enter the Value of C:3
The Area of the Triangle is: 28.0
PYTHON LAB
13
EX:NO:11
NUMBER OF CHARACTER IN THE STRING AND STORE
THEM IN A DICTIONARY DATA STRUCTURE
DATE:
SOURCE CODE:
str = input("Enter a string:")
dict = {}
for n in str:
keys = dict.keys()
if n in keys:
dict[n] += 1
else:
dict[n] = 1
print(dict)
OUTPUT:
Enter a string : AMMA
{'A': 1}
{'A': 1, 'M': 1}
{'A': 1, 'M': 2}
{'A': 2, 'M': 2}
PYTHON LAB
14
EX:NO:12
FIND THE PRIME NUMBER
DATE:
SOURCE CODE:
print("FIND THE PRIME NUMBER")
print("**********************")
x = int(input("Enter any positive number to chect whether it
is prime or not:"))
for i in range(2,x):
if x % 1 == 0:
print(x,"is not a prime number")
break
else:
print(x,"is a prime number:")
OUTPUT:
FIND THE PRIME NUMBER
Enter any positive number to check whether it is prime or
not:35
35 is not a prime number
PYTHON LAB
15
EX:NO:13
TO FIND LENGTH OF A STRING
DATE:
SOURCE CODE:
a = str(input("Enter the string:"))
b = 0
for i in a:
b += 1
print(b)
OUTPUT:
Enter the string: INDIA
5
PYTHON LAB
16
EX:NO:14
TO FIND THE ADDITION, SUBTRACTION,
MULTIPICATION,DIVISION
DATE:
SOURCE CODE:
def add(a,b):
return a+b
def sub(c,d):
return c-d
def mul(r,f):
return e*f
def div(g,h):
return g/h
print("********************************")
print("1.TO THE PROGRAM ADDITION")
print("2.TO THE PROGRAM SUBTRACTION")
print("3.TO THE PROGRAM MULTIPLICATION")
print("4.TO THE PROGRAM DIVISION")
print("*******************************")
choice = int(input("Enter your choice:"))
PYTHON LAB
17
if (choice == 1):
a = int(input("Enter 1st value:"))
b = int(input("enter 2nd value:"))
print(add(a,b))
elif (choice == 2):
c = int(input("Enter 1st value:"))
d = int(input("Enter 2nd value:"))
print(sub(c,d))
elif choice == 3:
e = int(input("Enter 1st value:"))
f = int(input("Enter 2nd value:"))
print(mul(e,f))
elif (choice == 4):
g = int(input("Enter 1st value:"))
h = int(input("Enter 2nd value:"))
print(div(g,h))
else:
print("Wrong choice")
PYTHON LAB
18
OUTPUT:
*******************************
1.TO THE PROGRAM ADDITION
2.TO THE PROGRAM SUBTRACTION
3.TO THE PROGRAM MULTIPLICATION
4.TO THE PROGRAM DIVISION
*******************************
Enter your choice:3
Enter 1st value:33
Enter 2nd value:65
2145
PYTHON LAB
19
EX:NO:15
FIND THE VALUE OF CHARACTER
DATE:
SOURCE CODE:
print("ASCII VALUE")
print("~~~~~~~~~~~~~")
c = str(input("Enter the Value :"))
print("The ASCII value of " + c + " is ", ord(c))
OUTPUT:
ASCII VALUE
~~~~~~~~~~~~~
Enter the Value :E
The ASCII value of E is 69
PYTHON LAB
20
EX:NO:16
THE DISPLAY CALENDAR
DATE:
SOURCE CODE:
import calendar
yy = int(input("Enter year:"))
mm = int(input("Enter month:"))
print(calendar.month(yy,mm))
OUTPUT:
Enter year:2002
Enter month:2
February 2002
Mo Tu We Th Fr Sa Su
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28
PYTHON LAB
21
EX:NO:17
COMPUTE THE POWER OF A NUMBER
DATE:
SOURCE CODE:
print("THE POWER OF NUMBER")
print("*******************")
base = 3
exponent = 4
result = 1
while exponent != 0:
result *= base
exponent -= 1
print(" ANSWER = ",str (result))
OUTPUT:
THE POWER OF NUMBER
*******************
ANSWER = 81
PYTHON LAB
22
EX:NO:18
TO CHECK IF A NUMBER IS POSITIVE, NEGATIVE, OR
ZERO
DATE:
SOURCE CODE:
def Numbercheck(a):
if a < 0:
print("Number Given by you is Negative")
elif a > 0:
print("Number Given by you is Positive")
else:
print("Number Given by you is Zero")
a = float(input("Enter a number as input value:"))
Numbercheck(a)
OUTPUT:
Enter a number as input value:6
Number Given by you is Positive
PYTHON LAB
23
EX:NO:19
DISPLAY THE MULTIPLICATION TABLE
DATE:
SOURCE CODE:
num = 12
for i in range(1,11):
print(i,'X',num,'=',num*i)
OUTPUT:
1 X 12 = 12
2 X 12 = 24
3 X 12 = 36
4 X 12 = 48
5 X 12 = 60
6 X 12 = 72
7 X 12 = 84
8 X 12 = 96
9 X 12 = 108
10 X 12 = 120
PYTHON LAB
24
EX:NO:20
FIND ALL DUPLICATES IN THE LIST
DATE:
SOURCE CODE:
def findduplicates(list):
b = []
for i in list:
if(i not in b):
b.append(i)
if(b == list):
print("There are not duplicates in the list")
else:
print(" There are duplicates in the list")
OUTPUT:
a = [3,5,6,7,8]
findduplicates(a)
There are no duplicates in the list
PYTHON LAB
25
Ex:no:21
Find the factorial of a number
Date:
Source code:
num = int(input("Enter a numbers:"))
factorial = 1
if num < 0:
print("Factorial does not exist for negative numbers")
elif num == 0:
print("The Factorial of a 0 is /")
else:
for i in range(1,num+1):
factorial *= i
print("The Factorial of",num,"is",factorial)
OUTPUT:
Enter a numbers:5
The Factorial of 5 is 120
PYTHON LAB
26
EX:NO:22
ADD TWO MATRICES
DATE:
Source code:
x =[[3,5,6],[6,3,1],[7,8,9]]
y=[[6,5,3],[1,6,3],[9,8,7]]
result=[[0,0,0],[0,0,0],[0,0,0]]
for i in range(len(x)):
for j in range(len(y)):
result[i][j]=x[i][j]+y[i][j]
for r in result:
print(r)
OUTPUT:
[9, 10, 9]
[7, 9, 4]
[16, 16, 16]
PYTHON LAB
27
EX:NO:23
COUNT THE NUMBER OF DIGITSPRESENT IN A
NUMBER
DATE:
SOURCE CODE:
num = 3651
count = 0
while num != 0:
num //=10
count += 1
print("Number of Digits:",count)
OUTPUT:
Number of Digits: 4
PYTHON LAB
28
EX:NO:24
FIND ALL THE UNIQUE ELEMENTS OF A LIST
DATE:
SOURCE CODE:
def findunique(list):
b = []
for i in list:
if(i not in b):
b.append(i)
if(b == list):
print("There are unique in the list")
else:
print("There are not unique in the list")
OUTPUT:
a = [3,5,24,6,34,89]
findunique(a)
There are unique in the list
b = [3,3,3,6,8,2]
findunique(b)
There are not unique in the list
PYTHON LAB
29
EX:NO:25
CONVERT DECIMAL TO BINARY,OCTAL AND
HEXADECIMAL
DATE:
SOURCE CODE:
dec = 344
print("The decimal value of",dec,"is:")
print(bin(dec),"in Binary")
print(oct(dec),"in Octal")
print(hex(dec),"in Hexadecimal")
OUTPUT:
The decimal value of 344 is:
0b101011000 in Binary
0o530 in Octal
0x158 in Hexadecimal
PYTHON LAB
30
EX:NO:25(a)
CONVERT CELSIUS TO FAHRENHEIT
DATE:
SOURCE CODE:
celsius = int(input("Enter the temperature in celsius:"))
f = (celsius * 9/5) + 32
print("Tempreature in Farenheit is:",f)
OUTPUT:
Enter the temperature in celsius:6
Tempreature in Farenheit is: 42.8
PYTHON LAB
31
EX:NO:25(B)
CONVERT KILOMETERS TO MILES
DATE:
SOURCE CODE:
kilometers = float(input("Enter value in kilometers:"))
conv_fac = 0.621371
miles = kilometers * conv_fac
print( "% 0.2f kilometers is equal to % 0.2f miles" %
(kilometers,miles))
OUTPUT:
Enter value in kilometers:6.00
6.00 kilometers is equal to 3.73 miles

More Related Content

What's hot

Iv unit-fuzzification and de-fuzzification
Iv unit-fuzzification and de-fuzzificationIv unit-fuzzification and de-fuzzification
Iv unit-fuzzification and de-fuzzificationkypameenendranathred
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVAVINOTH R
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C v_jk
 
Repetition Structure
Repetition StructureRepetition Structure
Repetition StructurePRN USM
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: InheritanceTareq Hasan
 
Alpha-beta pruning (Artificial Intelligence)
Alpha-beta pruning (Artificial Intelligence)Alpha-beta pruning (Artificial Intelligence)
Alpha-beta pruning (Artificial Intelligence)Falak Chaudry
 
Synchronization.37
Synchronization.37Synchronization.37
Synchronization.37myrajendra
 
switching techniques in data communication and networking
switching techniques in data communication and networkingswitching techniques in data communication and networking
switching techniques in data communication and networkingHarshita Yadav
 
Access modifiers
Access modifiersAccess modifiers
Access modifiersJadavsejal
 
Client server computing_keypoint_and_questions
Client server computing_keypoint_and_questionsClient server computing_keypoint_and_questions
Client server computing_keypoint_and_questionslucky94527
 
Polymorphism In Java
Polymorphism In JavaPolymorphism In Java
Polymorphism In JavaSpotle.ai
 
Control structures in java
Control structures in javaControl structures in java
Control structures in javaVINOTH R
 
Computer network switches & their structures
Computer network switches & their structuresComputer network switches & their structures
Computer network switches & their structuresSweta Kumari Barnwal
 
Procedure and Functions in pl/sql
Procedure and Functions in pl/sqlProcedure and Functions in pl/sql
Procedure and Functions in pl/sqlÑirmal Tatiwal
 
Control statements
Control statementsControl statements
Control statementsraksharao
 
Perceptron algorithm
Perceptron algorithmPerceptron algorithm
Perceptron algorithmZul Kawsar
 
Learn C# Programming - Variables & Constants
Learn C# Programming - Variables & ConstantsLearn C# Programming - Variables & Constants
Learn C# Programming - Variables & ConstantsEng Teong Cheah
 

What's hot (20)

Iv unit-fuzzification and de-fuzzification
Iv unit-fuzzification and de-fuzzificationIv unit-fuzzification and de-fuzzification
Iv unit-fuzzification and de-fuzzification
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
Java program structure
Java program structure Java program structure
Java program structure
 
Repetition Structure
Repetition StructureRepetition Structure
Repetition Structure
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
Alpha-beta pruning (Artificial Intelligence)
Alpha-beta pruning (Artificial Intelligence)Alpha-beta pruning (Artificial Intelligence)
Alpha-beta pruning (Artificial Intelligence)
 
Synchronization.37
Synchronization.37Synchronization.37
Synchronization.37
 
switching techniques in data communication and networking
switching techniques in data communication and networkingswitching techniques in data communication and networking
switching techniques in data communication and networking
 
Access modifiers
Access modifiersAccess modifiers
Access modifiers
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Client server computing_keypoint_and_questions
Client server computing_keypoint_and_questionsClient server computing_keypoint_and_questions
Client server computing_keypoint_and_questions
 
Polymorphism In Java
Polymorphism In JavaPolymorphism In Java
Polymorphism In Java
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
 
Computer network switches & their structures
Computer network switches & their structuresComputer network switches & their structures
Computer network switches & their structures
 
Procedure and Functions in pl/sql
Procedure and Functions in pl/sqlProcedure and Functions in pl/sql
Procedure and Functions in pl/sql
 
Control statements
Control statementsControl statements
Control statements
 
String Handling
String HandlingString Handling
String Handling
 
Perceptron algorithm
Perceptron algorithmPerceptron algorithm
Perceptron algorithm
 
Learn C# Programming - Variables & Constants
Learn C# Programming - Variables & ConstantsLearn C# Programming - Variables & Constants
Learn C# Programming - Variables & Constants
 

Similar to Python Lab Manual

CAPE Unit1 Computer Science IA Sample .pdf
CAPE Unit1 Computer Science IA Sample .pdfCAPE Unit1 Computer Science IA Sample .pdf
CAPE Unit1 Computer Science IA Sample .pdfIsaacRamdeen
 
ch03-parameters-objects.ppt
ch03-parameters-objects.pptch03-parameters-objects.ppt
ch03-parameters-objects.pptMahyuddin8
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docxjosies1
 
week4_python.docx
week4_python.docxweek4_python.docx
week4_python.docxRadhe Syam
 
C programs
C programsC programs
C programsMinu S
 
C PROGRAMS - SARASWATHI RAMALINGAM
C PROGRAMS - SARASWATHI RAMALINGAMC PROGRAMS - SARASWATHI RAMALINGAM
C PROGRAMS - SARASWATHI RAMALINGAMSaraswathiRamalingam
 
The Ring programming language version 1.6 book - Part 25 of 189
The Ring programming language version 1.6 book - Part 25 of 189The Ring programming language version 1.6 book - Part 25 of 189
The Ring programming language version 1.6 book - Part 25 of 189Mahmoud Samir Fayed
 
sql ppt for students who preparing for sql
sql ppt for students who preparing for sqlsql ppt for students who preparing for sql
sql ppt for students who preparing for sqlbharatjanadharwarud
 
Visual Basic
Visual BasicVisual Basic
Visual BasicVj NiroSh
 
functions2-200924082810.pdf
functions2-200924082810.pdffunctions2-200924082810.pdf
functions2-200924082810.pdfpaijitk
 
Structured query language functions
Structured query language functionsStructured query language functions
Structured query language functionsVineeta Garg
 
Practical File waale code.pdf
Practical File waale code.pdfPractical File waale code.pdf
Practical File waale code.pdfFriendsStationary
 
java experiments and programs
java experiments and programsjava experiments and programs
java experiments and programsKaruppaiyaa123
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]vikram mahendra
 
SQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankSQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankMd Mudassir
 

Similar to Python Lab Manual (20)

Mcq cpup
Mcq cpupMcq cpup
Mcq cpup
 
CAPE Unit1 Computer Science IA Sample .pdf
CAPE Unit1 Computer Science IA Sample .pdfCAPE Unit1 Computer Science IA Sample .pdf
CAPE Unit1 Computer Science IA Sample .pdf
 
ch03-parameters-objects.ppt
ch03-parameters-objects.pptch03-parameters-objects.ppt
ch03-parameters-objects.ppt
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
 
Useful c programs
Useful c programsUseful c programs
Useful c programs
 
week4_python.docx
week4_python.docxweek4_python.docx
week4_python.docx
 
C programs
C programsC programs
C programs
 
C PROGRAMS - SARASWATHI RAMALINGAM
C PROGRAMS - SARASWATHI RAMALINGAMC PROGRAMS - SARASWATHI RAMALINGAM
C PROGRAMS - SARASWATHI RAMALINGAM
 
c programming
c programmingc programming
c programming
 
The Ring programming language version 1.6 book - Part 25 of 189
The Ring programming language version 1.6 book - Part 25 of 189The Ring programming language version 1.6 book - Part 25 of 189
The Ring programming language version 1.6 book - Part 25 of 189
 
sql ppt for students who preparing for sql
sql ppt for students who preparing for sqlsql ppt for students who preparing for sql
sql ppt for students who preparing for sql
 
Visual Basic
Visual BasicVisual Basic
Visual Basic
 
pointers 1
pointers 1pointers 1
pointers 1
 
Parameters
ParametersParameters
Parameters
 
functions2-200924082810.pdf
functions2-200924082810.pdffunctions2-200924082810.pdf
functions2-200924082810.pdf
 
Structured query language functions
Structured query language functionsStructured query language functions
Structured query language functions
 
Practical File waale code.pdf
Practical File waale code.pdfPractical File waale code.pdf
Practical File waale code.pdf
 
java experiments and programs
java experiments and programsjava experiments and programs
java experiments and programs
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
 
SQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankSQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question Bank
 

More from Bobby Murugesan

Computer skills for web designing and video editing_Lab Manual.pdf
Computer skills for web designing and video editing_Lab Manual.pdfComputer skills for web designing and video editing_Lab Manual.pdf
Computer skills for web designing and video editing_Lab Manual.pdfBobby Murugesan
 
Sequence Types in Python Programming
Sequence Types in Python ProgrammingSequence Types in Python Programming
Sequence Types in Python ProgrammingBobby Murugesan
 
How to register in Swayam
How to register in SwayamHow to register in Swayam
How to register in SwayamBobby Murugesan
 
Green computing introduction
Green computing introductionGreen computing introduction
Green computing introductionBobby Murugesan
 

More from Bobby Murugesan (6)

Computer skills for web designing and video editing_Lab Manual.pdf
Computer skills for web designing and video editing_Lab Manual.pdfComputer skills for web designing and video editing_Lab Manual.pdf
Computer skills for web designing and video editing_Lab Manual.pdf
 
Sequence Types in Python Programming
Sequence Types in Python ProgrammingSequence Types in Python Programming
Sequence Types in Python Programming
 
Python The basics
Python   The basicsPython   The basics
Python The basics
 
Impressive Google Apps
Impressive Google AppsImpressive Google Apps
Impressive Google Apps
 
How to register in Swayam
How to register in SwayamHow to register in Swayam
How to register in Swayam
 
Green computing introduction
Green computing introductionGreen computing introduction
Green computing introduction
 

Recently uploaded

Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 

Recently uploaded (20)

Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 

Python Lab Manual

  • 2. PYTHON LAB 2 Table of Contents FIND THE LARGEST AMONG THREE NUMBERS .................................................................................... 3 FIND MEAN,MEDIAN,MODE FROM GIVEN NUMBER............................................................................ 4 SWAP TWO VARIABLES......................................................................................................................... 5 CHECK ARMSTRONG NUMBER.............................................................................................................. 6 TO FIND THE SQUAR ROOT ................................................................................................................... 7 TO CHECK IF A NUMBER IS ODD OR EVEN ............................................................................................ 8 REVERSE A NUMBER............................................................................................................................. 9 TO CHECK PALINDROME..................................................................................................................... 10 TO CHECK LEAP YEAR.......................................................................................................................... 11 FIND THE AREA OF TRIANGLE ............................................................................................................. 12 NUMBER OF CHARACTER IN THE STRING AND STORE THEM IN A DICTIONARY DATA STRUCTURE.... 13 FIND THE PRIME NUMBER.................................................................................................................. 14 TO FIND LENGTH OF A STRING............................................................................................................ 15 TO FIND THE ADDITION, SUBTRACTION, MULTIPICATION,DIVISION .................................................. 16 FIND THE VALUE OF CHARACTER........................................................................................................ 19 THE DISPLAY CALENDAR ..................................................................................................................... 20 COMPUTE THE POWER OF A NUMBER ............................................................................................... 21 TO CHECK IF A NUMBER IS POSITIVE, NEGATIVE, OR ZERO ................................................................ 22 DISPLAY THE MULTIPLICATION TABLE.............................................................................................. 23 FIND ALL DUPLICATES IN THE LIST ...................................................................................................... 24 Find the factorial of a number ............................................................................................................ 25 ADD TWO MATRICES .......................................................................................................................... 26 COUNT THE NUMBER OF DIGITSPRESENT IN A NUMBER ................................................................... 27 FIND ALL THE UNIQUE ELEMENTS OF A LIST....................................................................................... 28 CONVERT DECIMAL TO BINARY,OCTAL AND HEXADECIMAL............................................................... 29 CONVERT CELSIUS TO FAHRENHEIT.................................................................................................... 30 CONVERT KILOMETERS TO MILES ....................................................................................................... 31
  • 3. PYTHON LAB 3 EX:NO:1 FIND THE LARGEST AMONG THREE NUMBERS DATE: SOURCE CODE: a = int(input("A:")) b = int(input("B:")) c = int(input("C:")) if(a > b and a > b): print("Largest : ",a) elif(b > a and b > c): print("Largest : ",b) elif(c > a and c > b): print("Largest : ",c) OUTPUT: A:36 B:82 C:91 Largest : 91
  • 4. PYTHON LAB 4 EX:NO:2 FIND MEAN,MEDIAN,MODE FROM GIVEN NUMBER DATE: SOURCE CODE: print("FIND MEAN,MEDIAN,MODE") print("**********************") from statistics import mean, median, mode l = [ 36, 56, 76, 82, 27] print("MEAN:",mean(l)) print("MEDIAN:",median(l)) print("MODE:",mode(l)) print("**********************") OUTPUT: FIND MEAN,MEDIAN,MODE ********************** MEAN: 55.4 MEDIAN: 56 MODE: 36
  • 5. PYTHON LAB 5 EX:NO:3 SWAP TWO VARIABLES DATE: SORCE CODE: print("SWAP THE VARIABLES") print("*******************") a = 6 b = 3 temp = a a = b b = temp print("The Value of a After Swapping:",format(a)) print("The Value of a After Swapping:",format(b)) OUTPUT: SWAP THE VARIABLES ******************* The Value of a After Swapping: 3 The Value of a After Swapping: 6
  • 6. PYTHON LAB 6 EX:NO:4 CHECK ARMSTRONG NUMBER DATE: SOURCE CODE: print("CHECK ARMSTRONG NUMBER") print("_______________________") num = int(input("Enter the number:")) sum = 0 temp = num while temp > 0: digit = temp % 10 sum += digit ** 3 temp //= 10 if num == sum: print(num,"Is An Amstrong...") else: print(num,"Is An Amstrong...") OUTPUT: CHECK ARMSTRONG NUMBER _______________________ Enter the number:356 356 Is An Amstrong...
  • 7. PYTHON LAB 7 EX:NO:5 TO FIND THE SQUAR ROOT DATE: SOURE CODE: print(" The Square Root") print("~~~~~~~~~~~~~~~~~") import cmath n = int(input("N:")) result = cmath.sqrt(n) print("Square root of",n,"is",result) OUTPUT: The Square Root ~~~~~~~~~~~~~~~~ N :6 Square root of 6 is (2.449489742783178+0j)
  • 8. PYTHON LAB 8 EX:NO:6 TO CHECK IF A NUMBER IS ODD OR EVEN DATE: SOURCE CODE: print("ODD ARE EVEN NUMBER") print("___________________") num = int(input("Enter the number :")) if( num % 2) == 0: print(" {0} is even". format(num)) else: print(" {0} is odd". format(num)) OUTPUT: ODD ARE EVEN NUMBER ___________________ Enter the number :36 36 is even
  • 9. PYTHON LAB 9 EX:NO:7 REVERSE A NUMBER DATE: SOURCE CODE: print("REVERSE A NUMBER") print("*****************") num = int(input("Enter the number:")) reversed_num = 0 while num != 0: digit = num % 10 reversed_num = reversed_num * 10 + digit num //= 10 print("Reverse the number :" +str(reversed_num)) OUTPUT: REVERSE A NUMBER ***************** Enter the number:987654321 Reverse the number :123456789
  • 10. PYTHON LAB 10 EX:NO:8 TO CHECK PALINDROME DATE: SOURCE CODE: print("TO CHECK PALINDROME") print("*******************") s = str(input("ENTER THE STRING:")) def ispalindrome(s): return s == s [ : :-1] ans = ispalindrome(s) if ans: print(s,"is a palindrom") else: print(s,"is a palindrom") OUTPUT: TO CHECK PALINDROME ******************* ENTER THE STRING:AMMA AMMA is a palindrom
  • 11. PYTHON LAB 11 EX:NO:9 TO CHECK LEAP YEAR DATE: SOURCE CODE: print("CHECK LEAP YEAR") print("*****************") year = int(input("ENTER THE YEAR :")) if (year % 4) == 0: if (year % 100) == 0: if(year % 400) == 0: print("{0} is a leap year".format(year)) else: print("{0} is not a leap year".format(year)) else: print("{0} is a leap year".format(year)) else: print("{0} is a not a leap year".format(year)) OUTPUT: CHECK LEAP YEAR ***************** ENTER THE YEAR :2022 2022 is a not a leap year
  • 12. PYTHON LAB 12 EX:NO:10 FIND THE AREA OF TRIANGLE DATE: SOURCE CODE: print("AREA OF TRIANGLE") print("*****************") a = int(input("Enter the Value of A:")) b = int(input("Enter the Value of B:")) c = int(input("Enter the Value of C:")) s = (a + b + c)/2 area = (s*(s-a)*(s-b)*(s-c)**0.5) print("The Area of the Triangle is:",area) OUTPUT: AREA OF TRIANGLE ***************** Enter the Value of A:6 Enter the Value of B:5 Enter the Value of C:3 The Area of the Triangle is: 28.0
  • 13. PYTHON LAB 13 EX:NO:11 NUMBER OF CHARACTER IN THE STRING AND STORE THEM IN A DICTIONARY DATA STRUCTURE DATE: SOURCE CODE: str = input("Enter a string:") dict = {} for n in str: keys = dict.keys() if n in keys: dict[n] += 1 else: dict[n] = 1 print(dict) OUTPUT: Enter a string : AMMA {'A': 1} {'A': 1, 'M': 1} {'A': 1, 'M': 2} {'A': 2, 'M': 2}
  • 14. PYTHON LAB 14 EX:NO:12 FIND THE PRIME NUMBER DATE: SOURCE CODE: print("FIND THE PRIME NUMBER") print("**********************") x = int(input("Enter any positive number to chect whether it is prime or not:")) for i in range(2,x): if x % 1 == 0: print(x,"is not a prime number") break else: print(x,"is a prime number:") OUTPUT: FIND THE PRIME NUMBER Enter any positive number to check whether it is prime or not:35 35 is not a prime number
  • 15. PYTHON LAB 15 EX:NO:13 TO FIND LENGTH OF A STRING DATE: SOURCE CODE: a = str(input("Enter the string:")) b = 0 for i in a: b += 1 print(b) OUTPUT: Enter the string: INDIA 5
  • 16. PYTHON LAB 16 EX:NO:14 TO FIND THE ADDITION, SUBTRACTION, MULTIPICATION,DIVISION DATE: SOURCE CODE: def add(a,b): return a+b def sub(c,d): return c-d def mul(r,f): return e*f def div(g,h): return g/h print("********************************") print("1.TO THE PROGRAM ADDITION") print("2.TO THE PROGRAM SUBTRACTION") print("3.TO THE PROGRAM MULTIPLICATION") print("4.TO THE PROGRAM DIVISION") print("*******************************") choice = int(input("Enter your choice:"))
  • 17. PYTHON LAB 17 if (choice == 1): a = int(input("Enter 1st value:")) b = int(input("enter 2nd value:")) print(add(a,b)) elif (choice == 2): c = int(input("Enter 1st value:")) d = int(input("Enter 2nd value:")) print(sub(c,d)) elif choice == 3: e = int(input("Enter 1st value:")) f = int(input("Enter 2nd value:")) print(mul(e,f)) elif (choice == 4): g = int(input("Enter 1st value:")) h = int(input("Enter 2nd value:")) print(div(g,h)) else: print("Wrong choice")
  • 18. PYTHON LAB 18 OUTPUT: ******************************* 1.TO THE PROGRAM ADDITION 2.TO THE PROGRAM SUBTRACTION 3.TO THE PROGRAM MULTIPLICATION 4.TO THE PROGRAM DIVISION ******************************* Enter your choice:3 Enter 1st value:33 Enter 2nd value:65 2145
  • 19. PYTHON LAB 19 EX:NO:15 FIND THE VALUE OF CHARACTER DATE: SOURCE CODE: print("ASCII VALUE") print("~~~~~~~~~~~~~") c = str(input("Enter the Value :")) print("The ASCII value of " + c + " is ", ord(c)) OUTPUT: ASCII VALUE ~~~~~~~~~~~~~ Enter the Value :E The ASCII value of E is 69
  • 20. PYTHON LAB 20 EX:NO:16 THE DISPLAY CALENDAR DATE: SOURCE CODE: import calendar yy = int(input("Enter year:")) mm = int(input("Enter month:")) print(calendar.month(yy,mm)) OUTPUT: Enter year:2002 Enter month:2 February 2002 Mo Tu We Th Fr Sa Su 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
  • 21. PYTHON LAB 21 EX:NO:17 COMPUTE THE POWER OF A NUMBER DATE: SOURCE CODE: print("THE POWER OF NUMBER") print("*******************") base = 3 exponent = 4 result = 1 while exponent != 0: result *= base exponent -= 1 print(" ANSWER = ",str (result)) OUTPUT: THE POWER OF NUMBER ******************* ANSWER = 81
  • 22. PYTHON LAB 22 EX:NO:18 TO CHECK IF A NUMBER IS POSITIVE, NEGATIVE, OR ZERO DATE: SOURCE CODE: def Numbercheck(a): if a < 0: print("Number Given by you is Negative") elif a > 0: print("Number Given by you is Positive") else: print("Number Given by you is Zero") a = float(input("Enter a number as input value:")) Numbercheck(a) OUTPUT: Enter a number as input value:6 Number Given by you is Positive
  • 23. PYTHON LAB 23 EX:NO:19 DISPLAY THE MULTIPLICATION TABLE DATE: SOURCE CODE: num = 12 for i in range(1,11): print(i,'X',num,'=',num*i) OUTPUT: 1 X 12 = 12 2 X 12 = 24 3 X 12 = 36 4 X 12 = 48 5 X 12 = 60 6 X 12 = 72 7 X 12 = 84 8 X 12 = 96 9 X 12 = 108 10 X 12 = 120
  • 24. PYTHON LAB 24 EX:NO:20 FIND ALL DUPLICATES IN THE LIST DATE: SOURCE CODE: def findduplicates(list): b = [] for i in list: if(i not in b): b.append(i) if(b == list): print("There are not duplicates in the list") else: print(" There are duplicates in the list") OUTPUT: a = [3,5,6,7,8] findduplicates(a) There are no duplicates in the list
  • 25. PYTHON LAB 25 Ex:no:21 Find the factorial of a number Date: Source code: num = int(input("Enter a numbers:")) factorial = 1 if num < 0: print("Factorial does not exist for negative numbers") elif num == 0: print("The Factorial of a 0 is /") else: for i in range(1,num+1): factorial *= i print("The Factorial of",num,"is",factorial) OUTPUT: Enter a numbers:5 The Factorial of 5 is 120
  • 26. PYTHON LAB 26 EX:NO:22 ADD TWO MATRICES DATE: Source code: x =[[3,5,6],[6,3,1],[7,8,9]] y=[[6,5,3],[1,6,3],[9,8,7]] result=[[0,0,0],[0,0,0],[0,0,0]] for i in range(len(x)): for j in range(len(y)): result[i][j]=x[i][j]+y[i][j] for r in result: print(r) OUTPUT: [9, 10, 9] [7, 9, 4] [16, 16, 16]
  • 27. PYTHON LAB 27 EX:NO:23 COUNT THE NUMBER OF DIGITSPRESENT IN A NUMBER DATE: SOURCE CODE: num = 3651 count = 0 while num != 0: num //=10 count += 1 print("Number of Digits:",count) OUTPUT: Number of Digits: 4
  • 28. PYTHON LAB 28 EX:NO:24 FIND ALL THE UNIQUE ELEMENTS OF A LIST DATE: SOURCE CODE: def findunique(list): b = [] for i in list: if(i not in b): b.append(i) if(b == list): print("There are unique in the list") else: print("There are not unique in the list") OUTPUT: a = [3,5,24,6,34,89] findunique(a) There are unique in the list b = [3,3,3,6,8,2] findunique(b) There are not unique in the list
  • 29. PYTHON LAB 29 EX:NO:25 CONVERT DECIMAL TO BINARY,OCTAL AND HEXADECIMAL DATE: SOURCE CODE: dec = 344 print("The decimal value of",dec,"is:") print(bin(dec),"in Binary") print(oct(dec),"in Octal") print(hex(dec),"in Hexadecimal") OUTPUT: The decimal value of 344 is: 0b101011000 in Binary 0o530 in Octal 0x158 in Hexadecimal
  • 30. PYTHON LAB 30 EX:NO:25(a) CONVERT CELSIUS TO FAHRENHEIT DATE: SOURCE CODE: celsius = int(input("Enter the temperature in celsius:")) f = (celsius * 9/5) + 32 print("Tempreature in Farenheit is:",f) OUTPUT: Enter the temperature in celsius:6 Tempreature in Farenheit is: 42.8
  • 31. PYTHON LAB 31 EX:NO:25(B) CONVERT KILOMETERS TO MILES DATE: SOURCE CODE: kilometers = float(input("Enter value in kilometers:")) conv_fac = 0.621371 miles = kilometers * conv_fac print( "% 0.2f kilometers is equal to % 0.2f miles" % (kilometers,miles)) OUTPUT: Enter value in kilometers:6.00 6.00 kilometers is equal to 3.73 miles