LIST PROGRAM:
LIST INPUT & OUTPUT:
TUPLE PROGRAM:
TUPLE OUTPUT:
Perfect number, a positive integer that is equal to the sum of its proper divisors. The smallest perfect number is 6, which is the sum of 1, 2, and 3. Other perfect numbers are 28, 496, and 8,128.
Armstrong number: A number is called Armstrong number if it is equal to the sum of the cubes of its own digits. For example: 153 is an Armstrong number since 153 = 1*1*1 + 5*5*5 + 3*3*3 and 371 is an Armstrong number since 371=3*3*3+7*7*7+1*1*1.
A palindromic number (also known as a numeral palindrome or a numeric palindrome) is a number (such as 16461) that remains the same when its digits are reversed.
12. Write Algorithm and Python program to print all the numbers
divisible by 3 an
PROGRAM:
OUTPUT:
def writ_an_f():
fin=open("D:\\book.txt","r")
fout=open("D:\\story.txt","w")
s=fin.readlines()
for j in s:
if 'a' in j:
fout.write(j)
fout.close()
fin.close()
def cnt():
f=open("D:\\test2.txt","r")
cont=f.read()
print(cnt)
v=0
cons=0
l_c_l=0
u_c_l=0
for ch in cont:
if (ch.islower()):
l_c_l+=1
elif(ch.isupper()):
u_c_l+=1
ch=ch.lower()
if( ch in ['a','e','i','o','u']):
v+=1
elif (ch in ['b','c','d','f','g',
'h','j','k','l','m',
'n','p','q','r','s',
't','v','w','x','y','z']):
cons+=1
f.close()
print("Vowels are: ",v)
print("consonants are : ",cons)
print("Lower case letters are : ",l_c_l)
print("Upper case letters are : ",u_c_l)
#Main program
while True:
print("\n\nText files Menu driven program:")
print("1. Remove all the lines that contain" )
print(" the character `a’ in a file and write it" )
print(" to another file\n" )
print("2.Read a text file and display the" )
print(" number of vowels/ consonants/ uppercase/" )
print(" lowercase characters in the file\n" )
print("3. Exit\n")
ch=int(input("Enter your choice : "))
if ch==1:
writ_an_f()
elif ch==2:
cnt()
elif ch==3:
break
else:
print( " invalid choice ")