Now Again
Now Again
1
1
COMPUTER SCIENCE
PRACTICAL FILE
2
INDEX
S.no TOPIC Page No Signature
Practical - 1
Q)Input a welcome message and display it.
[PROGRAM FINISHED]
5
Practical - 2
Q)Input two numbers and display the larger/smaller
number.
[PROGRAM FINISHED]
6
Practical - 3
Q.Input three numbers and display the largest/smallest
number.
[PROGRAM FINISHED]
7
Practical - 4
Q)(a) Generate the following pattern using a nested
loop.
*
**
***
**** ***** n=int(input("enter
range(0,n):
for j in range(0,i+1):
print("*",end="")
print(" ") [OUTPUT]
8
[PROGRAM FINISHED]
b)12345
1234
123
12
1
for i in range(5,0,-1):
for j in range(1,i+1):
print(j,end="")
print()
9
[OUTPUT]
[PROGRAM FINISHED]
c) A
AB
ABC
ABCD
for i in range(1,6):
A=65
for j in range(0,i):
print(chr(A),end="")
A=A+1
print()
[OUTPUT]
10
[PROGRAM FINISHED]
11
Practical - 5
Q- Write a program to input the value of X and n and
print the sum of the following series:
(a)1+x+x2+x3+x4+................xn
x=int(input("enter x:"))
n=int(input("enter n:"))
s=0 for i in range(n):
s=s+(x**i)
print(s)
[OUTPUT]
[PROGRAM FINISHED]
(b)1-x+x2-x3+x4…….xn.
12
x=int(input("enter"))
n=int(input("enter"))
s=x for i in
range(1,n): z=i+1 if
i%2==0:
s=s+((x**z)/z)
else:
s=s-((x**z)/z)
print(s)
[OUTPUT]
[PROGRAM FINISHED]
(C)x-x2/2+x3/3-x4/4…………..xn
x=int(input("enter"))
n=int(input("enter"))
13
[PROGRAM FINISHED]
14
Practical - 6
Q-Determine whether a number is a perfect number, an
armstrong number or a palindrome.
#palindrome(12321 is palindrome)
number=int(input("enter any number:")) num=number
num1=number rev=0 while num>0: digit=num%10
rev=rev*10+digit num=int(num/10)
if number==rev:
print(number,'is a palindrome')
else:
print(number,'is not a palindrome')
#Armstrong number is equal to sum of cubes of each
digit
sum=0
temp=num1
15
while temp>0:
digit=temp%10
sum+=digit**3
temp//=10
if num1==sum:
print(num1,"is an Armstrong number")
else:
print(num1,"is not a Armstrong number")
#perfect number,a positive integer that is equal to
the sum of its proper divisors. sum1=0 for i in
range(1,number):
if(number%i==0):
sum1=sum1+i
if(sum1==number):
print(number,"the number is a perfect number
number.")
else:
print(number,"the number is not a perfect number.")
[OUTPUT]
16
Practical - 7
n=int(input("enter"))
flag=False for i in
range(2,n): if
n%i==0:
flag=True
if flag==True:
print("composite number")
else: print("prime number")
[OUTPUT]
17
[PROGRAM FINISHED]
Practical - 8
Q-Display the terms of the fibonacci series.
n=int(input("enter"))
a=0 b=1
print("",a,b,end="")
for i in range(n):
c=a+b a,b=b,c
print("",c,end=""
)
[OUTPUT]
[PROGRAM FINISHED]
18
Practical - 9
Q) Compute the greatest common divisor and least
multiple of two integers.
0)):
lcm = greater
break
greater += 1
print("The Least Common Multiple (LCM) is ", lcm)
[OUTPUT]
[PROGRAM FINISHED]
20
Practical - 10
str=input("Enter a string:")
w="" for element in str[::-
1]: w = w+element if
(str==w):
print(str, 'is a Palindrome string')
else: print(str,' is NOT a Palindrome
string')
[OUTPUT]
[PROGRAM FINISHED]
21
Practical - 11
[OUTPUT]
[PROGRAM FINISHED]
22
Practical -12
Q)Input a list of numbers and swap elements at the
even location with the elements at the odd location
Python Program.
[OUTPUT]
[PROGRAM FINISHED]
24
Practical – 13
Q)Input a list/tuple of elements and search for a given
element in the list/tuple Python Program. mylist = []
print("Enter 5 elements for the list: ") for i in
range(5):
value = int(input())
mylist.append(value)
25
[PROGRAM FINISHED
26
Practical - 14
Q)Input a list of numbers and find the smallest and largest
number from the list Python Program.
[OUTPUT]
[PROGRAM FINISHED]
27
Practical - 15
print(result)
[OUTPUT]
[PROGRAM FINISHED]