Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
14 views

Program Python

The document contains 16 coding exercises with objectives, procedures and results for finding sum and average, largest of 2 numbers, printing day of the week, finding smallest of 3 numbers, calculating factorial using while and for loops, checking palindrome and prime numbers, working with lists, tuples, sets and dictionaries, and defining functions to calculate area and perimeter of a rectangle.

Uploaded by

binila1125
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Program Python

The document contains 16 coding exercises with objectives, procedures and results for finding sum and average, largest of 2 numbers, printing day of the week, finding smallest of 3 numbers, calculating factorial using while and for loops, checking palindrome and prime numbers, working with lists, tuples, sets and dictionaries, and defining functions to calculate area and perimeter of a rectangle.

Uploaded by

binila1125
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Exercise: 1

Objective: Write a program to find sum and average of 2 number.

Apparatus Required: Python i

Procedure:

a=int(input("Enter the first number\n"))

b=int(input("Enter the second number\n"))

add=a+b

avg=add/2

print("Total=",add,"\nAverage=",avg)

Result: The program is successfully completed and the output is verified.

Exercise: 2

Objective: Write a program to check largest of 2 numbers using split method.

Apparatus Required: Python

Procedure:

a,b=input("Enter the two numbers\n").split()

if a>b:

print(a,"is largest")

else:

print(b,"is largest")

Result: The program is successfully completed and the output is verified.

Exercise: 3

Objective: Write a program to print day in a week using elif statement.

Apparatus Required: Python

Procedure:

d=int(input("enter the day number\n"))

if d==1:
print("Sunday")

elif d==2:

print("Monday")

elif d==3:

print("Thuesday")

elif d==4:

print("Wednesday")

elif d==5:

print("Thursday")

elif d==6:

print("Friday")

elif d==7:

print("Saturday")

else:

print("Ivalid day")

Result: The program is successfully completed and the output is verified.

Exercise: 4

Objective: Write a program to check smallest of 3 numbers using nested if statements.

Apparatus Required: Python

Procedure:

x=int(input("Enter the fisrt number\n"))

y=int(input("Enter the second number\n"))

z=int(input("Enter the third number\n"))

if x<y:

if x<z:

print(x,"is smallest")

else:
print(y,"is smallest")

else:

if y<z:

print(y,"is smallest")

else:

print(z,"is smallest")

Result: The program is successfully completed and the output is verified.

Exercise: 5

Objective: Write a program to find factorial of a numbers using while loop.

Apparatus Required: Python

Procedure:

n=int(input("Enter the number\n"))

i=1

fact=1

while i<=n:

fact=fact*i

i=i+1

print("Factorial=",fact)

Result: The program is successfully completed and the output is verified.

Exercise: 6

Objective: Write a program to check a number is palindrome or not using while loop.

Apparatus Required: Python

Procedure:

n=int(input("Enter the number"))

rev=0

temp=n

while n>0:
r=n%10;

rev=rev*10+r

n=n//10

if temp==rev:

print(temp,"is a palindrome number")

else:

print(temp,"is not a palindrome number")

Result: The program is successfully completed and the output is verified.

Exercise: 7

Objective: Write a program to check a number is prime or not using while loop.

Apparatus Required: Python

Procedure:

n=int(input("Enter the number\n"))

i=2

p=1

while i<=n/2:

if n%i==0:

p=0

break

i=i+1

if p==1:

print(n,"is prime number")

else:

print(n,"is not prime number")

Result: The program is successfully completed and the output is verified.

Exercise: 8

Objective: Write a program to find factorial of a number using for loop.


Apparatus Required: Python

Procedure:

n=int(input("Enter the number"))

i=1

fact=1

for i in range(i,n+1):

fact=fact*i

i=i+1

print("Factorial=",fact)

Result: The program is successfully completed and the output is verified.

Exercise: 9

Objective: Write a program to print multiplication table.

Apparatus Required: Python

Procedure:

n=int(input("Enter the number"))

i=1

for i in range(i,11):

m=n*i

print(i,"X",n,"=",m,"\n")

Result: The program is successfully completed and the output is verified.

Exercise: 10

Objective: Write a program to print Fibonacci series using for loop.

Apparatus Required: Python

Procedure:

n=int(input("Enter the number\n"))

f1=-1

f2=1
i=1

for i in range(i,n+1):

f3=f1+f2

print(f3,"\n")

f1=f2

f2=f3

Result: The program is successfully completed and the output is verified.

Exercise: 11

Objective: Write a program to check a number is Armstrong or not using for loop.

Apparatus Required: Python

Procedure:

n=int(input("Enter the number"))

sum=0

i=1

temp=n

for i in range(i,n+1):

r=n%10

sum=sum+r*r*r

n=n//10

if temp==sum:

print(temp,"is armstrong number")

else:

print(temp,"is not armstrong number")

Result: The program is successfully completed and the output is verified.


Exercise: 12

Objective: Write a program to print a list functions program.

Apparatus Required: Python

Procedure:

num=[1,2,4,3,6,2,2,10,2]

lang=["python","cpp","c","java"]

print(num)

print(lang)

print("Repetition Operator",num*2)

print("Maximum of lang",max(lang))

print("Count of 2:",num.count(2))

print("Sort lang:",sorted(lang))

lang.append("html")

print("Add element in last position",lang)

Result: The program is successfully completed and the output is verified.

Exercise: 13

Objective: Write a program to print a tuple functions program.

Apparatus Required: Python

Procedure:

num=(13,21,43,3,6,2,22,10,25)

lang=("python","cpp","c","java")

print(num)

print(lang)

print("Slice Operator with specified range",num[2:6])

print("Minimum of lang",max(lang))

print("index 2:",num.count(2))

print("Sort lang in descending order:",sorted(lang,reverse=True))


print("sum of num",sum(num))

Result: The program is successfully completed and the output is verified.

Exercise: 14

Objective: Write a program to print a set functions program.

Apparatus Required: Python

Procedure:

num1={13,21,43,3,6,2,22,10,25}

num2={13,21,43,3,6,2,28,12,19,39,72}

print("Union of 2 sets:",num1.union(num2))

print("Intersection of 2 sets",num1.intersection(num2))

print("Difference of 2 sets:",num1.difference(num2))

print("issubset of sets",num1.issubset(num2))

num1.clear()

print("Clear the set1",num1)

Result: The program is successfully completed and the output is verified.

Exercise: 15

Objective: Write a program to print a dictionary functions program.

Apparatus Required: Python

Procedure:

student={"name":"Arun","age":12,"Gender":"Male","Regno":1111,"Branch":"CBSE"}

student2=student.copy()

print("Student2 Dictionary:",student2)

for x in student.keys():

print(x)

student.update({"Branch":"State"})

print(student)

Result: The program is successfully completed and the output is verified.


Exercise: 16

Objective: Write a program to print area and perimeter of rectangle using module.

Apparatus Required: Python

Procedure:

def area(l,b):

return l*b

def perimeter(l,b):

return 2*(l+b)

l=int(input("Enter length:"))

b=int(input("Enter breadth:"))

print("Area of Rectangle is:",area(l,b))

print("Perimeter of Rectangle is:",perimeter(l,b))

Result: The program is successfully completed and the output is verified.

You might also like