Posts

Showing posts from September, 2021

Python program to reverse Entered String

 n=input("Enter String :") n=n[::-1] print(n)

Python program to count number of words entered

 n=input("Enter String :") f=len(n) count=0 for i in range(0,f):     z=ord(n[i])     if z==32:         count+=1 print("Number of words : ",count+1)

Python program to count number of vowels and consonants in string

 n=input("Enter String :") n=n.lower() f=len(n) count=0 for i in range(0,f):     z=ord(n[i])     if z==97 or z==101 or z==105 or z==111 or z==117:         count+=1 print("Number of vowels : ",count) print("Number of consonants : ",f-count)

Python program to toggle Case of string

 x=input("Enter String ") f=len(x) for i in range(0,f):     z=ord(x[i])     if z>=65 and z<91:         print(chr(z+32),end=" ")     elif z>=97 and z<122:         print(chr(z-32),end=" ")

Python program to convert strings to upper and lower cases

#uppercase conversion  n=input("Enter String :") n=n.upper() print(n) #lowercase conversion n=input("Enter String :") n=n.lower() print(n)

Python program to check if strings are same or not

 n=input("Enter String 1:") j=input("Enter String 2:") if n==j:     print("They are same") else:     print("They are Different")

Python program to combine 2 strings

 n=input("Enter String 1:") j=input("Enter String 2:") print("Combined : ",n+j)

Python program to find the length of string

 n=input("Enter String:") j=len(n) print("It's Length : ",j)

Python program to print table of entered number

 n=int(input("Enter N : ")) for i in range(1,11):     print(n," x ",i," = ",n*i)

Python program to find Factorial of Entered Number

 fac=1 n=int(input("Enter N : ")) for i in range(n,0,-1):     fac=fac*i print(n,"! = ",fac)

Python program to find Square root of entered Number

 from math import * n=int(input("Enter N : ")) for i in range(1,n+1):     s=sqrt(i)     print(i,"=",s)

Python program to check if it is a Duck Number or not

 t=r=x=fag=0 n=int(input("ENTER N : ")) while n!=0:     t=n%10     if t==0:        fag+=1     n=n//10 if fag>0:     print("It's a Duck Number") else:     print("It's not a Duck Number")

Python program to print N prime numbers

 count=1 ex=3 n=int(input("ENTER N : ")) print(2) while count!=n:     tmp=0     for i in range(2,ex):         if ex%i==0:             tmp+=1     if tmp==0:         count+=1         print(ex)     ex+=1

Python program to print Prime numbers till N

 n=int(input("ENTER N : ")) for i in range(2,n+1):     temp=0     for j in range(2,i):         if i%j==0:             temp+=1     if temp==0:         print(i)

Python program for checking if entered number is Special or not

sum=0 fac=1 n=int(input("Enter N : ")) x=n while n!=0:     t=n%10     fac=1     for i in range(t,0,-1):         fac=fac*i     sum+=fac     n=n//10  if sum==x:     print("IT's A SPECIAL NUMBER!") else:     print("IT's NOT A SPECIAL NUMBER!")

Python program for finding Factorial of a number

fac=1 n=int(input("Enter N : ")) for i in range(n,0,-1):     fac=fac*i print(n,"! = ",fac)

Python program for reversing an Entered Number

 t=r=0 n=int(input("ENTER N : ")) while n!=0:     t=n%10     r=r*10+t     n=n//10 print('REVERSE : ',r) 

Python program for finding Frequency of digits

 n1=n2=n3=n4=n5=n6=n7=n8=n9=t=n0=0 n=int(input("ENTER N : ")) while n!=0:     t=n%10     if t==1:         n1+=1     elif t==2:         n2+=1     elif t==3:         n3+=1     elif t==4:         n4+=1     elif t==5:         n5+=1     elif t==6:         n6+=1     elif t==7:         n7+=1     elif t==8:         n8+=1     elif t==9:         n9+=1     elif t==0:         n0+=1     n=n//10 print("0 :",n0) print("1 :",n1) print("2 :",n2) print("3 :",n3) print("4 :",n4) print("5 :",n5) print("6 :",n6) print("7 :",n7) print("8 :",n8) print("9 :",n9)

Python program for finding Max among digits

 maxx=0 n=int(input("ENTER N : ")) while n!=0:     t=n%10     if t>maxx:         maxx=t     n=n//10     print("Largest Digit : ",maxx)

Python program for checking if Number is prime or not

 flag=0 n=int(input("Enter N : ")) for i in range(2,n,1):     if n%i==0:         flag+=1 if flag==0:     print(n," is prime ") else:     print(n," is not prime ")

Python program to check if number is Perfect or not

 sum=0 n=int(input("Enter N : ")) for i in range(1,n,1):     if n%i==0:         sum+=i if sum==n:     print("It is a perfect Number") else:     print("It is NOT a perfect Number")

Python Program to check if number is Twisted Prime or not

 flag=x=fag=r=0 n=int(input("Enter N : ")) for i in range(2,n,1):     if n%i==0:         flag+=1 if flag==0:     while n!=0:         t=n%10         r=r*10+t         n=n//10     for i in range(2,r,1):         if r%i==0:            fag+=1     if fag==0:         print("It is Twisted Prime ") else:     print(n," is not twisted prime ")

Python program for Sum of digits

 s=0 n=int(input("ENTER N : ")) while n!=0:     t=n%10     s+=t     n=n//10     print("SUM OF DIGITS : ",s)

Python program for finding GCD and LCM of 2 Numbers

 gcd=0 n1=int(input("Enter N1 : ")) n2=int(input("Enter N2 : ")) if n2>n1:     n1,n2=n2,n1     for i in range(2,n1,1):     if n1%i==0 and n2%i==0:         gcd=i print("GCD : ",gcd)     lcm=0 lcm=n1*n2/gcd print("LCM : ",lcm)