EX. NO.
: 01
DIFFERENT DATA TYPES
DATE:
AIM:
To write a python program to read and write the variables of different data types.
PROCEDURE:
1
SOURCE CODE:
num=int(input("Enter the value of number:"))
amt=float(input("Enter the value of amount:"))
pi=float(input("Enter the value of pi:"))
code=str(input("Enter the value of code:"))
pop_of_india=int(input("Enter the valu of population of india:"))
msg=str(input("Enter the value of message:"))
print("\n NUM="+str(num)+"\n AMT="+str(amt)+"\n PI="+str(pi)+"\n CODE="+str(code)+
"\n population_of_India="+str(pop_of_india)+ "\n Message="+str(msg))
OUTPUT:
Enter the value of number: 55
Enter the value of amount: 879.9
Enter the value of pi: 3.14
Enter the value of code: “G”
Enter the value of population of India: 89076556
Enter the value of message: “HELLO”
NUM=55
AMT=879.9
PI=3.14
CODE=G
Population_of_india=89076556
Message=HELLO
2
RESULT:
3
EX. NO.: 02
ARITHMETIC MANIPULATION OF INTEGERS
DATE:
AIM:
To write a python program to perform addition, subtraction, multiplication, division,
integer division, and modulo division on two integer numbers.
PROCEDURE:
4
SOURCE CODE:
a=int(input("Enter an integer:"))
b=int(input("Enter an integer:"))
print("The addition of",a,"and",b,"is:",a+b)
print("The subtraction of",a,"and",b,"is:",a-b)
print("The multiplication of",a,"and",b,"is:",a*b)
print("The integer division of",a,"and",b,"is:",int(a/b))
print("The float division of",a,"and",b,"is",float(a/b))
print("The modulo division of",a,"and",b,"is:",a%b)
OUTPUT:
Enter an integer:5
Enter an integer:3
The addition of 5 and 3 is: 8
The subtraction of 5 and 3 is: 2
The multiplication of 5 and 3 is: 15
The integer division of 5 and 3 is: 1
The float division of 5 and 3 is 1.6666666666666667
The modulo division of 5 and 3 is: 2
5
RESULT:
6
EX. NO.: 03
IDENTIFICATION OF VOWELS
DATE:
AIM:
To write a python program to determine whether the character entered is vowel or not.
PROCEDURE:
7
SOURCE CODE:
ch=input("Enter any character:")
if(ch=="A" or ch=="E" or ch=="I" or ch=="O" or ch=="U"):
print(ch,"is a vowel")
elif(ch=="a" or ch=="e" or ch=="i" or ch=="o" or ch=="u"):
print(ch,"is a vowel")
else:
print(ch,"is not a vowel")
OUTPUT:
Enter any character: “A”
A is a vowel
8
RESULT:
9
EX. NO.: 04
FACTORIAL NUMBER
DATE:
AIM:
To write a python program using loop to calculate factorial of a number.
PROCEDURE:
10
SOURCE CODE:
num=int(input("Enter the number:"))
if(num==0):
fact=1
fact=1
for i in range(1,num+1):
fact=fact*i
print("Factorial of",num,"is",fact)
OUTPUT:
Enter the number: 5
Factorial of 5 is 120
11
RESULT:
12
EX. NO.: 05
SQUARE ROOT OF A NUMBER
DATE:
AIM:
To write a python program to calculate square root of a number and to demonstrate the
use of pass, break, and continue statements.
PROCEDURE:
13
SOURCE CODE:
import math
while(1):
num=int(input("Enter the number:"))
if(num==999):
pass
break
elif(num<=0):
print("Square root of negative number cannot be calculated")
continue
else:
print("Square root of",num,"=",[Link](num))
OUTPUT:
Enter the number:4
Square root of 4 = 2.0
Enter the number:5
Square root of 5 = 2.23606797749979
14
RESULT:
15
EX. NO.: 06
TO CHECK ODD OR EVEN USING FUNCTION
DATE:
AIM:
To write a python program using a function and return statement, to check whether a
number is even or odd.
PROCEDURE:
16
SOURCE CODE:
def evenodd(a):
if(a%2==0):
return 1
else:
return-1
a=int(input("Enter the number:"))
flag=evenodd(a)
if(flag==1):
print("Number is even")
if(flag==-1):
print("Number is odd")
OUTPUT:
Enter the number:3
Number is odd
17
RESULT:
18
EX. NO.: 07
FIBONACCI SERIES USING RECURSION
DATE:
AIM:
To write a python program to print the Fibonacci series using recursion.
PROCEDURE:
19
SOURCE CODE:
def fibonacci(n):
if(n<2):
return 1
return(fibonacci(n-1)+fibonacci(n-2))
n=int(input("Enter the number of terms:"))
for i in range(n):
print("Fibonacci(",i,")=",fibonacci(i))
OUTPUT:
Enter the number of terms:5
Fibonacci( 0 )= 1
Fibonacci( 1 )= 1
Fibonacci( 2 )= 2
Fibonacci( 3 )= 3
Fibonacci( 4 )= 5
20
RESULT:
21
EX. NO.: 08
REVERSING AN ARRAY
DATE:
AIM:
To write a python program to reverse the order of the items in the array.
PROCEDURE:
22
SOURCE CODE:
arr=[1,2,3,4,5]
print("Original array")
for i in range(0,len(arr)):
print(arr[i])
print("Array in reverse order")
for i in range(len(arr)-1,-1,-1):
print(arr[i])
OUTPUT:
Original array
1
2
3
4
5
Array in reverse order
5
4
3
2
1
23
RESULT:
24
EX. NO.: 09
REMOVING VOWELS IN A STRING
DATE:
AIM:
To write a python program that accepts a string from the user and redisplays the same
string after removing vowels.
PROCEDURE:
25
SOURCE CODE:
def remove_vowels(s):
new_str=" "
for i in s:
if i in "aeiouAEIOU":
pass
else:
new_str+=i
print("The string without using vowels is:",new_str)
str=input("\n Enter a string:")
remove_vowels(str)
OUTPUT:
Enter a string: PYTHON PROGRAMMING LANGUAGE
The string without using vowels is: PYTHN PRGRMMNG LNGG
26
RESULT:
27
EX. NO.: 10
REMOVING DUPLICATES FROM A LIST
DATE:
AIM:
To write a python program to remove all duplicates from the list.
PROCEDURE:
28
SOURCE CODE:
num_list=[1,2,3,4,5,6,7,6,5,4]
print("Original list:",num_list)
i=0
while i<len(num_list):
num=num_list[i]
for j in range(i+1,len(num_list)):
val=num_list[j]
if val==num:
num_list.pop(j)
i=i+1
print("List after removing duplicates:",num_list)
OUTPUT:
Original list: [1, 2, 3, 4, 5, 6, 7, 6, 5, 4]
List after removing duplicates: [1, 2, 3, 4, 5, 6, 7]
29
RESULT:
30
EX. NO.: 11
DISPLAYING POSITIVE FROM A LIST
DATE:
AIM:
To write a python program that has a list of numbers (both positive as well as negative)
and to make a new tuple that has only positive numbers from the list.
PROCEDURE:
31
SOURCE CODE:
Tup=(-10,1,2,-9,3,4,-8,5,6)
newTup=()
for i in Tup:
if i>0:
newTup+=(i,)
print("Original List:", Tup)
print("Positive:",newTup)
OUTPUT:
Original List: (-10, 1, 2, -9, 3, 4, -8, 5, 6)
Positive: (1, 2, 3, 4, 5, 6)
32
RESULT:
33
EX. NO.: 12
DICTIONARY OF RADIUS AND CIRCUMFERENCE
DATE:
AIM:
To write a python program to create a dictionary of radius of a circle and its
circumference.
PROCEDURE:
34
SOURCE CODE:
print("Enter -1 to exit")
circumference={}
while True:
r=float(input("Enter the radius:"))
if(r==-1):
break
else:
Dict={r:2*3*3.14*r}
[Link](Dict)
print(circumference)
OUTPUT:
Enter -1 to exit
Enter the radius:2
Enter the radius:3
Enter the radius:-1
{2.0: 37.68, 3.0: 56.519999999999996}
35
RESULT:
36