Python Program Files
Program 7 = Asterisk / Numbers / Alphabets in Triangle Format
INPUT:
#Program to print the Asterisk Symbol in Triangle Format
print("Asterisk in triangle format")
n=int(input("Enter the number of coloumns you want the asterisks to be printed = "))
for i in range(0,n):
for j in range(0,i+1):
print('*',end='')
print()
print("______________________________________________")
#Program to print the Numbers in Triangle Format
print("Numbers in Triangle Format ")
x=int(input("Enter the number of coloumns you want the numbers to be printed = "))
for i in range(x,0,-1):
for j in range(1,i+1):
print(j,end=' ')
print()
print("_______________________________________________")
#Program to print the alphbets in Triangle Format
print("Alphabets in Triangle Format ")
x=int(input("Enter the number of coloumns you want the alphabets to be printed = "))
for i in range(1,x+1):.
a=65
for j in range(1,i+1):
b=chr(a)
print(b,end=' ')
a+=1
print()
Program 8 = Perfect Number
INPUT:
#Program to find whether a given number is a Perfect Number or Not
n=int(input("Enter a positive number = "))
sum1=0
List=[]
for i in range (1,n):
if (n%i==0):
List.append(i)
sum1 = sum1+i
print("The Divisors of the number",n,"are",List)
print("The Sum of the divisors of",n,"=",sum1)
if (sum1 == n):
print("Since the number",n,"and the sum of the divisors",sum1,"are
same")
print("The number",n,"is a Perfect Number !")
else:
print("Since the number",n,"and the sum of the divisors",sum1,"are not
same")
print("The number",n,"is not a Perfect number!")
Program 9 = Armstrong Number
INPUT:
# Python program to check if the number is an Armstrong number or not
num = int(input("Enter a positive number: "))
sum = 0
temp = num
while temp!=0:
digit = temp % 10
sum += digit**3
temp//=10
print("The Entered Number is ",num)
print("Sum of the Cubes of each digit of the Number",num,"=",sum)
if num == sum:
print("Since the given number",num,"and the sum of the cubes of digits
of ",num,"are same")
print("The Entered number ",num,"is an Armstrong number")
else:
print("Since the given number",num,"and the sum of the cubes of digits
of ",num,"are not same")
print("The Entered number ",num,"is not an Armstrong number")
Program 10 = To Check whether a Number is a Palindrome or Not
INPUT:
#Program to Check whether a number is a palindromic or not
n=int(input("Enter a positive number :"))
temp=n
rev=0
while(n!=0):
dig=n%10
rev=rev*10+dig
n=n//10
print("The Entered number is ",temp)
print("The Reverse of",temp,"is",rev)
if(temp==rev):
print("Since the Entered number",temp,"and its reverse",rev,"are
same")
print("The number",temp,"is a Palindrome!")
else:
print("Since the Entered number",temp,"and its reverse",rev,"are
same")
print("The number",temp,"is a Palindrome!")
Program 12 = Fibonacci Sequence
INPUT:
nterms = int(input("How many terms? "))
n1, n2 = 0, 1
count = 0
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)
nth = n1+n2
n1=n2
n2=nth
count += 1
Program 13 = GCD and LCM of Two Numbers
INPUT:
# Python program to find G.C.D of two numbers
x=int(input("Enter a number "))
y=int(input("Enter 2nd 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
print("The Entered Numbers are",x,"and",y)
print("The GCD of",x,"and",y,"=",hcf)
# Python Program to find the L.C.M. of two input number
# choose the smallest number
if x < y:
greater = x
else:
greater = y
while True:
if((greater % x ==0) and (greater % y ==0)):
lcm = greater
print(" The LCM of",x,"and",y,"=",lcm)
break
greater += 1
Program 14 = Count and display the number of vowels, consonants,
uppercase, lowercase characters in string
INPUT:
# Program to count vowels,consonant, digits and special character in a
given string.
line = input("Enter a line")
l=u=d=a=s=v=c=sp=0
for t in line:
if t.isalpha():
a += 1
if t.isupper():
u += 1
elif t.islower():
l += 1
if (t=='a' or t == 'e' or t == 'i'or t == 'o'or t == 'u'):
v += 1
else :
c += 1
elif t.isdigit():
d +=1
elif t.isalnum()!=True and a!= '':
s += 1
elif t.isspace():
sp +=1
print("Entered String is ",l)
print("Total Number of Characters in the Entered String = ",len(line))
print("Number of Alphabets = ",a)
print("Number of Vowels = ",v)
print("Number of Consonants = ",c)
print("Number of Uppercase Alphabets = ",u)
print("Number of Lowercase Alphabets = ",l)
print("Number of Digits = ",d)
print("Number of Symbols = ",s)
print("Number of Spaces = ",sp)