Posts

Python Program which will find all such numbers between 1000 and 3000 (both included) such that each digit of the number is an even number.The numbers obtained should be printed in a comma-separated sequence on a single line

  x='' for i in range (1000,3001):     n=i     flag =1     while (n>0):         rem = n%10         if (rem%2!=0):             flag = 0             break         n=n//10     if (flag == 1):         x+= str(i)+' , ' print (x)

Python Program to input any string and make it the encrypt code by 2 charactern

s= input ('Enter a string') x='' len = len(string) for i in range (len):     ch = string[i]     if (ch=='y'):         x=x+'a'     elif (ch=='z'):         x=x+'b'     elif (ch=='Y'):         x=x+'A'     elif (ch=='Z'):         x=x+'B'     else :         a = ord(ch) + 2         x=x+ chr(a) print ('String after encrption: ', x)

Python Program to perform all arithmetic operations in menu

print(''' main menu 1.add 2.sub 3.div 4.milt 5.exit''') n1=int(input('enter any n1')) n2=int(input('enter any n2')) while True:   ch=int (input('enter your choice'))   if ch==1:     print(n1+n2)   elif ch==2:     print(n1-n2)   elif ch==3:     print(n1*n2)   elif ch==4:     print(n1/n2)   elif ch==5:     print('you have exited!')     break   else:     print('invalid choses')

Python Program to input your percentage and print grade

' ''  Percentage(%)           Grade      91-100                   A      81-90                    B      71-80                    C      0-70                     D   ''' per=int(input('enter perentage')) if per>=91 and per<=100:   print('Grade A') elif per>=81 and per<=90:   print('Grade B') elif per>=71 and per<=80:   print('Grade c') elif per>=0 and per<=70:   print('Grade D') else:   print('invalid marks')

Python Program to input percentage and print result

cri=int(input('enter criteria(percentage) for pass and fail')) per=int(input('enter perentage')) if per>=cri:   print('pass') else:   print('fail')

Python Program to input any number and check whether it is perfect number or not

n = int(input ('Enter a no.')) sum = 0 n1=n for i in range (1,n):     if (n%i==0):         sum = sum + i if (sum ==n1):     print (n1,' is a perfect no.') else :     print (n1,' is not a perfect no.')

Python Program to print sum of series # 1/1! + 2/2! + 3/3! + ....... + n/n!

# sum = 1/1! + 2/2! + 3/3! ... n/n! n = int (input ('Enter value for n: ')) sum =0 for i in range (1,n+1):     f=1     for j in range(1,i+1):         f=f*j     sum+= (i/f) print ('Sum of series= ', sum)

Python Program to input N number and print sum of N geometric terms

  # sum = a + ar + ar**2 + ar**3 + ..... + ar**n n= int (input ('Enter no of terms')) a= int (input ('Enter value for a ')) r= int (input ('Enter value for r')) sum=a for i in range (1,n+1):     sum = sum + (a*r**i)     print (a*r**i, sum) print ('Sum of series = ',sum)

Python Program to print N number of geometric terms

a =int(input(" Enter First Number of an G.P Series: : ")) n = int(input(" Enter the Total Numbers in this G.P Series: : ")) r = int(input("Please Enter the Common Ratio : ")) total = 0 value = a print("\nG.P Series :", end = " ") for i in range(n):     print("%d " %value, end = " ")     total = total + value     value = value * r print("\nThe Sum of Geometric Progression Series = " , total)

Python Program to input any number and check whether it is automatic or not

n=0 cnt=0 n=int(input('Enter any no...')) sq=n**2 print(sq) while(n>0):   cnt=cnt+1   n=n//10 no=sq%(10**cnt) print(no) if(n==no):   print('The no. is automorphic') else:   print('The no. is not automorphic') 

Python Program to input 3 digit number and print the sum of all digits

n=int(input('3 digit no.')) sum=0 for i in range(3):   a=n%10   sum+=a   n=n//10 print(sum) 

Python Program to input any number and check whether it is positive, negative or zero

n=int(input('enter any number')) if (n>0):   print(n,'is positive') elif (n<0):   print(n,'is negative') else:   print(n,'zero') 

Python Program to input any number and check whether it is odd or even

n=int(input('enter any number')) if n<0:     print(n,':number is negative') else:     if n%2==0:         print(n,':number is even')     else:         print(n,':number is odd')

Python Program to calculate compound interest

p=int(input('enter principle amount')) r=int(input('enyer rate of intrest')) t=int(input('time of intrest')) ci=p*(1+r/100)**t print('compound intrest',ci)

Python Program to calculate simple interest

p=int(input('enter principle amount')) r=int(input('enyer rate of intrest')) t=int(input('time of intrest')) si=p*r*t/100 print('simple intrest',si)

Python Program to print circumference of circle

r=int(input('enter radius of circle')) pie=22/7 circum=pie*r*2 print('circumference of circle=',circum)

Python Program to input radius of circle and print area of circle

r=int(input('enter radius of circle')) pie=22/7 area=pie*r**2 print('area of circle=',area)

Python Program to input two dates and to print gap between them # calculate your age

dd = int(input ('Enter Date: ')) mm = int(input ('Enter Month: ')) yy = int(input ('Enter Year: ')) td = int(input ('Enter Today\'s Date: ')) tm = int(input ('Enter Today\'s Month: ')) ty = int(input ('Enter Today\'s Year: ')) ay=ad=am=0 if (mm<tm):     ay=ty-yy     if (mm==(tm-1)):         if (dd>tm):             am=0     else:         if (dd>tm):             am = tm-mm-1         else:             am = tm-mm         elif (mm>tm):     ay=ty-yy-1     if (dd<td):         am = 12-mm+tm     else:         am=11-mm+tm         else :         if (dd<td):         ay=ty-yy         ad = td - dd         am=0     elif (dd>td):         ay=ty-yy-1         am=11         if ( mm==2 or mm== 4 or mm==6 or mm==8 or mm==9 or mm==11 or mm==1):             ad = 31-dd+td         elif (mm== 5 or mm==7 or mm==10 or mm==12):             ad = 30-dd+td         else:            if (ty%4==0):               ad = 29-dd+td            else:

Python Program to input your name, class and age and print them

name=input('enter your name') class=int(input('enter your class') age=int(input('enter your age') print(name,"is studying in",class,"and",age,"years old")