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

PRACTICAL NO:1

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)

Num1, Num2, Num3 = Num2 , Num3 , Num1


Print( “AFTER SWAP: “)
Print( “Num1: “,Num1)
Print( “Num2: “,Num2)
Print( “Num3; “,Num3)
PRACTICAL NO : 2
OUTPUT:
 Enter the number – 1: 10
 Enter the number – 2: 20
 Enter the number – 3: 10
 After swap.
Num1:20
Num2:30
Num3:10
PRACTICAL NO: 2
RESULT:

The entered number 1, 2, 3 is obtained same by inputting three


numbers and by swapping them in python program
PRACTICAL NO: 3

SOURCECODE:

a=float(input(‘Enter the first number:’))


b= float(input(‘Enter the second number:’))
c= float(input(‘Enter the operator[/,*,+,-]:’)

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:

 Enter the 1st number : 8


 Enter the 2nd number : 2
 Enter the operator [/,*,+,-]:/
 8.0/2.0

PRACTICAL NO:3
RESULT:

The entered 1st number and 2nd number obtained is same by


inputting the two number and an arithmetic operator and by displaying
the expected output in python program.

PRACTICAL NO: 4
SOURCE CODE:

a=int(input(‘Enter the year:’))


if a%4==0:

print(‘This year is a leap year’)

else:

print(‘This year is not a leap year’)

PRACTICAL NO:4
OUTPUT:

 Enter the year: 2020


 This is the leap year.

PRACTICAL NO:4
RESULT:

The year which is obtained is a leap year while on checking


whether it is a leap year or not? In python program. [ ENTERED YEAR
2020]. Therefore the result obtained is a leap year.

PRACTICAL NO: 5
SOURCE CODE:

a=int(input(‘Enter the first integer:’))

b=int(input(‘Enter the second integer’))

c=int(input(‘Enter the third integer’))

if a>b and a>c:

print(a, ‘is the largest integer’)

if b>a and b>c:

print(b, ‘is the largest integer’)

if c>a and c>b:

print(c, ‘is the largest integer’)

else:

print(‘All or any two are equal’)

PRACTICAL NO: 5
OUTPUT:

 Enter the first digit: 56


 Enter the second digit number :34
 Enter the third digit number : 67
 67 is the largest number.

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:

Even = int(input(“Enter the input”))


total=0

for numbers in range (1, Even+1):


if (number % 2 == 0 ):
print(number)
total = total + number

print(“The sum of even numbers”,total)


Odd = int(input(“Enter the input”))
Total = 0

for numbers in range in range (1, Odd+1):


If (numbers % 2!=0):
Print(number)
Total = total + number
Print(‘The sum of the odd numbers”, total)

PRACTICAL NO:6
OUTPUT:

Enter the input 25 Enter the input 15

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:

In the entered input of 25 the sum was obtained as 156 and


in the entered input of 15 the sum was obtained as 64 by calculating and
printing the sum of even and odd integers of first n natural numbers in
python program.

PRACTICAL NO: 7
SOURCE CODE:

n = int(input(“Enter a number : “))

sum = 0

while (n !=0):

sum = sum +(n%10)

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’):

Print(“The given character ,’ch,’ is the vowel”)


Else:

Print(“The given character,”ch,” is the consonant”)

PRACTICALNO:8

OUTPUT:
o Please enter the character as you wish: A, the given
character is vowel.

o Please enter the character as your wish: S, the given


character is consonents.

PRACTICAL NO:8

RESULT:
On entering the character as our wish : A the given character
is vowel

And on entering the character as our wish : S the given


character is a consonant on accepting the character from the user and
display whether it is a vowel or consonant by python program.

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.

In Case2,on entering the month number 6 the name June


has been got as the result.

In Case3,on entering the month number 13 the respond was


as “invalid output”.

In Case4, on entering the month number 15 the respond was


as “invalid output”.

This is to by inputting the data of birth of the user to find the


year, month, and the date of the user by python program.

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:

print(n, ”is a prime number”)


#if the number is less than 1, it’s also not a prime
number.

Else:

Print(n, ”is not a prime number”)

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.

In these three patterns all the result was obtained I same


form as it appeared in the form of rows by generate the following
patterns using the nested loops methods by python program.

PRACTICAL NO: 13

SOURCE CODE:
x=float(input(‘Enter the value of x:”))

n=int(input(‘Enter the value of n (for x**n):’))

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.

On entering the value of n(for n**n) as 6 we got the value of n**n


as 6

And the sum of digit of these first 6 terms is 1093.

This is by finding the sum of series s= 1+ x2 + x3 + x4 ……+xn

By python program.

PRACTICAL NO :14

SOURCE CODE:
# GCD PROGRAM

num1 = int(input(“Enter the 1st number:”))


num2 = int(input(“Enter the 2nd number:”))
i=1
while(i < num1 and i <= num2):
if(num1 % i == 0 and num2 % i == 0):

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

14 Compute the Greatest Common Divisor and Least Common


Multiple of two integers
15 Visualization

You might also like