PRACTICAL FILE
PRACTICAL FILE
Sol:
str=input("Enter a Welcome message")
print(str)
1
Program 3: Input three numbers and display the
largest number.
Sol:
n1=int(input("Enter first Number"))
n2=int(input("Enter Second Number"))
n3=int(input("Enter Third Number"))
if n1>n2:
if n1>n3:
print("Largest is:",n1)
else:
print("Largest is:",n3)
else:
if n2>n3:
print("Largest is:",n2)
else:
print("Largest is:",n3)
2
Program 4: Given two integers x and n, compute 𝑥n.
Sol:
x=int(input("Enter value for x"))
n=int(input("Enter value for n"))
val=1
i=1
while i<=n:
val=val*x
i=i+1
3
Program 5: Write a program to input the value of x
and n and print the sum of the following series:
S=1+x+x2+x3+x4+x5+……..xn
4
Program 6: Write a program to input the value of x
and n and print the sum of the following series:
S=1-x+x2-x3+x4-x5+……..xn
sol:
i=i+1
print("The sum of the series is:",s)
5
Program 7:Write a program to enter a number and
print whether it is Palindrome Number or not?
Sol:
n=int(input("Enter a Number"))
m=n
s=0
while n>0:
r=n%10
s=s*10+r
n=n//10
if s==m:
print("Palindrome")
else:
print("Not Palindrome")
6
Program 8: Write a program to enter a number and
print whether it is Armstrong Number or not?
Sol:
n=int(input("Enter a Number"))
m=n
s=0
while n>0:
r=n%10
s=s+r*r*r
n=n//10
if s==m:
print("Armstrong")
else:
print("Not Armstrong")
7
Program 9: Write a program to enter a number and
print whether it is Prime Number or not?
Sol:
n=int(input("Enter a Number"))
i=2
while i<n:
if n%i==0:
break
i=i+1
if i==n:
print("Prime")
else:
print("Not Prime")
8
Program 10: Write a program to enter a number and
print whether it is Perfect Number or not?
Sol:
n=int(input("Enter a Number"))
sum=0
for i in range(1,n):
if n%i==0:
sum=sum+i
if sum==n:
print("Perfect")
else:
print("Not Perfect")
9
Program 11: Write a program to print Fibonacci
sequence.
Sol:
10
Program 12: Write a program to enter a string and
count total vowels and consonants in it.
Sol:
11
Program 13: Write a program to enter a string and
count total lower case, upper case and others in
it.
Sol:
12
Program 14: Write a program to enter a string and
print whether it is Palindrome or not? convert the
case of characters in a string.
Sol:
if my_str==rev_str:
print("The string is a palindrome.")
else:
print("The string is not a palindrome.")
13
Program 15: Write a program to create a list and
print the smallest element of the list.
Sol:
List=[]
ch='y'
while ch=='y':
n=int(input("Enter a number"))
List.append(n)
ch=input("Wnat to add more element to the
List?(y/n) ")
small=List[0]
for i in List:
if i<small:
small=i
14
Program 16: Write a program to create a tuple and
print the smallest element of the tuple.
Sol:
Tuple=()
ch='y'
while ch=='y':
n=int(input("Enter a number"))
Tuple=Tuple+(n,)
ch=input("Wnat to add more element to the
List?(y/n) ")
small=Tuple[0]
for i in Tuple:
if i<small:
small=i
15
Program 17: Write a program to search a number
from a list.
Sol:
List=[12,13,14,15,16,17]
n=int(input("Enter the number to search from the
list"))
found=False
for i in range(0,len(List)-1,1):
if List[i]==n:
print("Element found at:",i+1)
found=True
if found==False:
print("Element not found")
16
Program 18: Write a program to reverse the content
of the list.
Sol:
nums = [1,2,3,4,5,6,7,8,9]
print(nums)
length = len(nums)
for i in range(0,length//2,1):
t=nums[i]
nums[i]= nums[length-1-i]
nums[length-1-i]=t
print(nums)
17
Program 19: Input a list of numbers and swap
elements at the even location with the elements at
the odd location
Sol:
nums = [1,2,3,4,5,6,7,8,9]
print(nums)
length = len(nums)
for i in range(0,length,4):
if(i+2<length):
nums[i], nums[i+2] = nums[i+2], nums[i]
if(i+3<length):
nums[i+1], nums[i+3] = nums[i+3], nums[i+1]
print(nums)
18
Program 20: Create a dictionary with the roll
number, name and marks of n students in a class
and display the names of students who have marks
above 75.
Sol:
n = int(input("Enter number of students: "))
result = {}
for i in range(0,n,1):
print("Enter Details of student No.", i+1)
print(result)
19