Professional Documents
Culture Documents
Ai - 2
Ai - 2
SOURCE CODE:
Num1=int(input(“ENTER THE NUMBER -1: ”))
Num2=int(input(“ENTER THE NUMBER -2: “))
Print(“BEFORE SWAP: “)
Print(“AFTER SWAP: “)
Print(“Num1: “, Num1)
Print(“Num2: “, NUM2)
Num1,num2=num2,num1
Print(“AFTER SWAP: “)
Print(“Num1: “, Num1)
Print(“Num2: “, Num2)
PRACTICAL NO:1
OUTPUT:
Enter the value of x ? = 2
Enter the value of y ? = 3
Before swapping numbers: 2 3
After swapping numbers: 3 2
PRACTICAL NO:1
RESULT:
The entered value of x and y in python program is obtained
same by inputting
Two numbers and swapping them.
PRACTICAL NO:2
SOURCE CODE:
NUM1=int(input(“ENTER THE NUMBER-1: “))
NUM2=int(input(“ENTER THE NUMBER-2: “))
Num3=Int(input(“ENTER THE NUMBRT-3: “))
print(“BEFORE SWAP: ”)
print(“Num1: “,Num1)
print(“Num2; “,Num2)
print(“Num3:”,Num3)
SOURCECODE:
if c==’/’:
r=a/b
print(a,c,b,’=’,r)
elif c==’*’:
r=a+b
print(a,c,b,’=’,r)
elif c==’+’:
r=a+b
print(a,c,b,’=’,r)
elif c==’-‘:
r=a-b
print(‘Invalid operator’)
PRACTICAL: 3
OUTPUT:
PRACTICAL NO:3
RESULT:
PRACTICAL NO: 4
SOURCE CODE:
else:
PRACTICAL NO:4
OUTPUT:
PRACTICAL NO:4
RESULT:
PRACTICAL NO: 5
SOURCE CODE:
else:
PRACTICAL NO: 5
OUTPUT:
PRACTICAL NO: 5
RESULT:
Among the first, second and third digit, the third digit was
obtained as the largest number by making use of if-else statement in
python program.
PRACTICAL NO: 6
SOURCE CODE:
PRACTICAL NO:6
OUTPUT:
2 1
4 3
6 5
8 7
10 9
12 11
14 13
16 15
18
20
22
24
Sum:156 Sum:64
PRACTICAL NO: 6
RESULT:
PRACTICAL NO: 7
SOURCE CODE:
sum = 0
while (n !=0):
n=n/10
print(sum)
PRACTICAL NO: 7
OUTPUT:
o Enter a number: 123.
o Sum of these number is 6.
PRACTICAL NO: 7
RESULT:
On entering a number 123 the sum of these numbers where
6 on inputting a number and printing the sum of the digits in the given
numbers by python program.
PRACTICALNO:8
SOURCE CODE:
Ch=input(“Please enter the character as your wish:”)
If(ch==’a’ or ch==’A’ or ch==’e’ or ch==’E’or ch==’I’ or ch==’I’
Or ch==’oor ch==’O’or ch==’u’ or ch==’U’):
PRACTICALNO:8
OUTPUT:
o Please enter the character as you wish: A, the given
character is vowel.
PRACTICAL NO:8
RESULT:
On entering the character as our wish : A the given character
is vowel
PRACTICAL NO: 9
SOURCE CODE:
X=int(input(“Enter the month number:”))
if (x==1):
print(“January”)
if (x==2):
print(“February”)
if (x==3):
print(“March”)
if (x==4):
print(“April”)
if (x==5):
print(“May”)
if (x==6):
print(“June”)
if (x==7):
print(“July”)
if (x==8):
print(“August”)
if (x==9):
print(“September”)
if (x==10):
print(“October”)
if (x==11):
print(“November”)
if (x==12):
print(“December”)
if (x<1 or x>12):
print(“Invalid input”)
PRACTICAL NO: 9
OUTPUT:
o Case1:
Enter the month number: : 1, Jan.
o Case2:
Enter the month number: :6, June.
o Case3:
Enter the month number: : 13, invalid output
o Case4:
Enter the month number: : 15, invalid output.
PRACTICAL NO: 9
RESULT:
In Case1, on entering the month number 1 the name January
has been got as the result.
PRACTICAL NO: 10
SOURCE CODE:
n=int(input(“Enter the number:”))
i=1
while(i<=10)
t=n*i
print(n,”x”,I,”=”,t)
i=i+1
PRACTICAL NO:10
OUTPUT:
o Enter the number : 6
o 6*1=6
o 6*2=12
o 6*3=18
o 6*4=24
o 6*5=30
o 6*6=36
o 6*7=42
o 6*8=48
o 6*9=54
o 6*10=60
PRACTICAL NO:10
RESULT:
On entering the number 6 we found that the tables of 6 upto
th
its 10 time was obtained by inputting a number and display the table of
that number by python program.
PRACTICAL NO:11
SOURCE CODE:
n=int(input(“Enter the number:”))
#Check if the number is greater than 1
If n>1:
For i in range(2, int(n/2)+1):
If(n%i)==0:
Print(num,”is not a prime number”)
Break
else:
Else:
PRACTICAL NO: 11
OUTPUT:
5 is a prime number.
PRACTICAL NO: 11
RESULT:
The number 5 as result is a prime number on by entering a
number and check if it’s a prime number or not by python program.
PRACTICAL NO: 12
SOURCE CODE:
row=in(input(“Enter the number or rows:”))
print(“Pattern -1”)
for i in range(0, row + 1, 1):
for j in range(1, I + 1):
print(‘*’ , end=’ ‘)
print(“”)
print(“Pattern -2”)
for i in range(0, row + 1,1):
for j in range(1, 5-i+1):
print(j, end=’ ‘)
print(“”)
print(“Pattern -3”)
for i in range(0, row + 1,1):
for j in range(65, 65+i):
print(chr(j), end=’ ‘)
print(“”)
PRACTICAL NO: 12
OUTPUT:
Pattern- 1
Enter the number of rows=5
*
**
***
****
*****
Pattern- 2
Enter the number of rows=5
12345
1234
123
12
1
Pattern- 3
Enter the number of rows=5
A
AB
ABC
ABCD
ABCDE.
PRACTICAL NO: 12
RESULT:
In pattern 1 on entering the number of rows as 5 we got the result.
In pattern 2 on entering the number of rows as 5 we got the result.
In pattern 3 on entering the number of rows as 5 we got the result.
PRACTICAL NO: 13
SOURCE CODE:
x=float(input(‘Enter the value of x:”))
s=0
for a in range(n+1):
s+=x**a
print(‘Sum of first’,n,’terms:’,s)
PRACTICAL NO: 13
OUTPUT:
o Enter the value of n:3
o Enter the value of n(for n**n):6
o Sum of the first 6 terms:1093
PRACTICAL NO:13
RESULT:
On entering the value of n as 3. We got the value of n as 3.
By python program.
PRACTICAL NO :14
SOURCE CODE:
# GCD PROGRAM
gcd = i
i=i+1
print(“Greatest Common Divisor (GCD) is”, gcd)
# LCM PROGRAM
PRACTICAL NO: 14
OUTPUT:
o Enter the first num:3
o Enter the second num:5
o GCD is 1
o LCM is 15
PRACTICAL NO:14
RESULT:
On entering the 1st number as 3 and the 2nd number as 5 and
GCD of these both numbers is 1 and the LCM of these two numbers is
15, this is by computing the greatest common divisor and least common
multiple of the integers is python program.
PRACTICAL NO:15
SOURCE CODE:
# Import libraries
From matplotlib import pyplot as plt import numpy as np
# Creating dataset
Cars = [‘
LAMBORGHINI’,’TESLA’,’BHUGATI’,’ROLCEROYCE’,’PAG
ANI’, ’PORSCHE’].
Data = [50,32,41,47,48,25].
# Creating plot
Fig = plt.figure(figsize =(10,7))
Plt.pie(data, labels = cars)
# Show pie plot
plt.show()
plt.bar(cars,data)
# show pie plot
plt.show()
PRACTICAL NO: 15
OUTPUT:
PIE CHART:
Sales
PORSCHE BHUGATI
TESLA ROLCEROYCE
PAGANI LAMBORGHINI
GRAPHICAL CHART:
6
0
PORCHE BHUGATI TESLA ROLCEROYCE PAGANI LAMBORGINI
CAR SALES
PRACTICAL NO: 15
RESULT:
The expected output we obtained were a PIE CHART and
GRAPHICAL CHART. As given as follows:
PIE CHART:
Sales
PORSCHE BHUGATI
TESLA ROLCEROYCE
PAGANI LAMBORGHINI
GRAPHICAL CHART:
6
5 PORSCHE
BHUGATI
4
TESLA
3
ROLCEROYCE
2
PAGANI
1 LAMBORGHINI
0
PORSCHE BHUGATI TESLA ROLCEROYCE PAGANI LAMBORGINI
Therefore the result obtained was pie chart and as graphically chart
based data’s by visualization plot bar and pie chart using matplotbils
library by python program.
INDEX
S.NO NAME OF THE PROGRAM PAGE NO
1 Input two numbers and swap them.
2 Input three numbers and swap them
3 Arithmetic operator and displays the computed
4 Check if it is a leap year or not
5 Find largest among three integers. Make use of if-else statement
6 Sum of even and odd integers of the first n natural numbers
7 Print the sum of digits in the given number
8 Display whether the given Character is vowel or consonant
9 Get the name of the Month in a Year
10 Input a number and display the table of that number
11 Check a given number is prime or not
12 Patterns using nested loops
13 Sum of series : s= 1+ x+ x2 + x3 + x4 ……+xn