THEORY
THEORY
THEORY
OUTPUT:-
PROGRAM 2
#CODE TO CHECK IF THE IMPUTED NUMBER IS PERFECT OR
NOT
OUTPUT:-
PROGRAM 3
#CODE TO CHECK IF THE ENTERED NUMBER IS ARMSTRONG
OR NOT
num = int(input("Enter a number: "))
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
if num == sum:
print(num, "is an Armstrong number")
else:
print(num, "is not an Armstrong number")
OUTPUT:-
PROGRAM 4
#CODE TO FIND FACTORIAL OF THE ENTERED NUMBER
OUTPUT:-
PROGRAM 5
#CODE TO PRINT THE FIBONACCI SERIES TILL THE IMPUTED VALUE
n1, n2 = 0, 1
count = 0
nterms = int(input("For how many terms you want to print the
seeries:"))
if nterms <= 0:
print("Please enter a positive integer")
elif nterms == 1:
print("Fibonacci sequence upto",nterms,":")
print(n1)
else:
print("Fibonacci sequence:")
while count < nterms:
print(n1,end=" ")
nth = n1 + n2
n1 = n2
n2 = nth
count += 1
OUTPUT:-
PROGRAM 6
#CODE TO CHECK IF THE ENTERED STRING IS PALINDROME OR
NOT
OUTPUT:-
PROGRAM 7
#CODE TO RECURSIVELY FIND THE FACTORIAL OF A NATURAL
NUMBER
def recur(n):
if n == 1:
return n
else:
return n*recur(n-1)
num =int(input("Enter a number to find factorial:"))
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
print("The factorial of", num, "is", recur(num))
OUTPUT:-
PROGRAM 8
#CODE TO READ A CSV FILE
import csv
with open('poem.csv', 'r') as file:
reader = csv.reader(file)
for row in reader:
print(row)
OUTPUT:-
PROGRAM 9
#CODE TO REMOVE ALL LINE THAT CONTAINS ‘A’ IN A FILE AND
WRITE THEM IN ANOTHER FILE
PROGRAM 10
#CODE TO READ A TEXT FILE AND DISPLAY THE NUMBERS OF
VOWELS/CONSONANTS/UPPERCASE/LOWERCASE CHARACTERS
v=c=u=l=0
x=open('poem.txt','r')
r=x.read()
for i in r:
if i in "aeiouAEIOU": #vovel count
v+=1
if i.lower() in "bcdfghjklmnpqrstvwxyz": #consonants count
c+=1
if i.isupper(): #upper case count
u+=1
if i.islower(): #lower case count
l+=1
print("Number of vowels in flie:",v)
print("Number of consonants in flie:",c)
print("Number of uppercase in flie:",u)
print("Number of lowercase in flie:",l)
x.close()
OUTPUT:-
PROGRAM 11
#CODE