0% found this document useful (0 votes)
246 views

Computer Science Program File

The document contains 7 computer programs with their summaries and page numbers. Program 1 finds the largest and smallest numbers in a list. Program 2 finds the third largest number in a list. Program 3 tests if a number is prime. Program 4 checks if a string is a palindrome. Program 5 computes x to the power of n. Program 6 computes the greatest common divisor and lowest common multiple of two numbers. Program 7 checks if a number is an Armstrong number.

Uploaded by

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

Computer Science Program File

The document contains 7 computer programs with their summaries and page numbers. Program 1 finds the largest and smallest numbers in a list. Program 2 finds the third largest number in a list. Program 3 tests if a number is prime. Program 4 checks if a string is a palindrome. Program 5 computes x to the power of n. Program 6 computes the greatest common divisor and lowest common multiple of two numbers. Program 7 checks if a number is an Armstrong number.

Uploaded by

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

Computer Science File

INDEX
PRACTICAL PROGRAM NAME PG.NO TEACHERS
NO. SIGN
1 PROGRAM TO FIND THE 2
LARGEST AND SMALLEST
NUMBERS IN A LIST
2 PROGRAM TO FIND THE THIRD 3
LARGEST NUMBER IN A LIST

3 PROGRAM TO TEST FOR 4


PRIMARILY.....

4 PROGRAM TO FIND WHETHER A 5


STRING IS A PALINDROME OR
NOT......

5 PROGRAM TO COMPUTE XN OF 6
TWO GIVEN INTEGERS X AND
N......

6 PROGRAM TO COMPUTE THE 7


GREATEST COMMON DIVISOR
AND LOWEST COMMON
MULTIPLE.....

7 PROGRAM TO CHECK IF NO. IS 9


ARMSTRONG OR NOT

Teacher’s Sign- Page 1


Computer Science File

PROGRAM - 1
#PROGRAM TO FIND THE LARGEST AND SMALLEST
NUMBERS IN A LIST .........

lst = []
num = int(input("How many numbers: "))

for n in range(num):
numbers = int(input("Enter number "))
lst.append(numbers)

print("Maximum element in the list is :", max(lst),


"\nMinimum element in the list is ",min(lst))

Teacher’s Sign- Page 2


Computer Science File

PROGRAM - 2
# PROGRAM TO FIND THE THIRD LARGEST
NUMBER IN A LIST

a =[]
n = int(input("Enter number of elements: "))
for i in range(1,n+1):
b=int(input("Enter element:"))
a.append(b)
a.sort()
print("Third largest element is :",a[n-3])

Teacher’s Sign- Page 3


Computer Science File

PROGRAM – 3
# PROGRAM TO TEST FOR PRIMARILY.....
var = 1
while var== 1:
num = int(input("Enter a number : "))

if num>1:
for i in range(2,num):
if (num%i)==0:
print(num,"is not a prime number")
break
else:
print(num,"is a prime number")
else:
print(num,"is not a prime number")

Teacher’s Sign- Page 4


Computer Science File

PROGRAM - 4
# PROGRAM TO FIND WHETHER A STRING IS A
PALINDROME OR NOT......
var = 1
while var== 1:

string = input("Enter string:")


if string == string[::-1]:
print(string, "is a palindrome")
else:
print(string, "is a not a palindrome")

Teacher’s Sign- Page 5


Computer Science File

PROGRAM - 5
# PROGRAM TO COMPUTE X**N OF TWO GIVEN
INTEGERS X AND N......
var = 1
while var== 1:

x = int(input("Enter the first no.: "))


n = int(input("Enter the second no.: "))

a = x**n

print("The answer of",x,"raise to power",n,"is",a)

Teacher’s Sign- Page 6


Computer Science File

PROGRAM – 6
#PROGRAM TO COMPUTE THE GREATEST
COMMON DIVISOR AND LOWEST COMMON
MULTIPLE.....
var = 1
while var== 1:
x = int(input("Enter your first number: "))
y = int(input("Enter your second number: "))

if x>y :
smaller = y
else:
smaller = x
for i in range(1,smaller+1):
if ((x%i==0) and (y%i==0)):
hcf=i
Teacher’s Sign- Page 7
Computer Science File

lcm= (x*y)/hcf
print("The HCF of ",x, "and ",y,"is",hcf)
print("The LCM of ",x, "and ",y,"is",lcm)

Teacher’s Sign- Page 8


Computer Science File

PROGRAM - 7
#PROGRAM TO CHECK IF NO. IS ARMSTRONG OR
NOT
input_num = (input("Enter any number : "))
digit_len = len(str(input_num))

try:
arm_num =0
val = int(input_num)
while val>0:
reminder = val%10
arm_num += reminder ** digit_len
val //= 10

if int(input_num) == arm_num:

Teacher’s Sign- Page 9


Computer Science File

print(input_num, "is an ARMSTRONG


NUMBER")
else:
print(input_num, "is not an ARMSTRONG
NUMBER")

except ValueError :
print("That's not a valid number, Try Again !!!!!")

Teacher’s Sign- Page 10

You might also like