Posts

Python Program to print star(*) rhombus of side length 3.

n=3 j=n-1 print(' '*(n)+'*') for i in range(1,2*n):     if i>n:         print(' '*(i-n)+'*'+' '*(2*j-1)+'*')     else:         print(' '*(n-i)+'*'+' '*(2*i-1)+'*') if n>1:     print(' '*n+'*')

Python program to calculate the area of a trapezoid.

  height = float(input("Height of trapezoid: ")) base_1 = float(input('Base one value: ')) base_2 = float(input('Base two value: ')) area = ((base_1 + base_2) / 2) * height print("Area is:", area)

Python program to convert radian to degree

pi=22/7 radian = float(input("Input radians: ")) degree = radian*(180/pi) print(degree)

Python program to convert degree to radian.

  pi=22/7 degree = float(input("Input degrees: ")) radian = degree*(pi/180) print(radian)

Python Program to print a kajukatri shape

n=7 spc=n*2+1 for row in range(1,n+1):     x=''     x=' '*spc      for col in range(1,row+1):        x=x+str(col)+' '      for col in range(row-1,0,-1):     x=x+str(col)+' '     print(x)   spc=spc-2  spc=spc+4 for row in range(n-1,0,-1):     x=''     x=' '*spc      for col in range(1,row+1):         x=x+'* '         for col in range(row-1,0,-1):            x=x+'* '  print(x)  spc=spc+2

Python Program to input and string and print total number of characters in that (without len()) # working of len() function

str = input('Enter String') c=0 str=list(str) while str !=[]:      c+=1      str.pop() print(c)

Python Program to print all permutations using those three variables a,b,c=0,0,0. Output : 000,001,…… 999

for i in range (10):      for j in range(10):          for k in range (10):             x=str(i)+str(j)+str(k)             print (x)

Python Program to input any sentence and sub-string print the index of given sub-string if found else print -1

  mainstring=input('Enter any sentence : ') tofind=input('Enter any word to find : ') l1=len(tofind) temp=False for i in range(len(mainstring)-l1+1):     twochar=mainstring[i:i+l1]     if twochar==tofind:        #print('Found at index : ',i)        temp=True     break if temp==True:     print('Found at index : ',i) else:     print('Not found at ',-1)

Python  Program to input a string and check whether it is palindrome or not

original=input('Enter Any Number : ') reverse=original[::-1] if original==reverse:  print('The number you entered is a palindrome number!') else:  print('The number you entered is not a palindrome number!')

Python Program to input any number and print a star triangle

num=int(input('Enter any value : ')) for i in range(num+1):    print('*'*i)

Python Program to input any sentence and reverse it word by word

sen=input('enter sentence') r=sen.split(' ') x=' ' for i in r:     x+=i[::-1]+' ' print(x)