Posts

PythonProgram to input decimal number and print binary of the number

x='' n=int(input('Enter any n')) while n>0:   rem=n%2   n=n//2   x=x+str(rem) print(x[::-1])

Python Program to print the reverse order of string

str=input("Enter word") s=str.reverse print(s)

Python Program to Input 3 variable's value and print the biggest variable

  x =int( input ( 'Enter x' ))   y =int( input ( 'Enter y' ))  z =int( input ( 'Enter z' ))  if (x>=y and x>=z):      print (x, ' is greatest' )  elif (y>=z and y>=z):      print (y, ' is greatest' )  else :      print (z, ' is greatest' )

Python Program to Input no. of persons ,sales amt.amt. Find commission of that person based on given condition sales amt. comm

'''0-10000 10%  10001-20000 20%  20001-50000 25%  >50000 30% '''  no=int( input ( 'Enter person number' ))  sa=int( input ( 'Enter sales amt' ))  com =0  if (sa>= 0 and sa<= 10000 ):      com= 0.1 * sa  elif (sa<= 20000 and sa> 10000 ):      com= 0.2 * sa  elif (sa> 20000 and sa<= 50000 ):      com= 0.25 * sa  else :      com= 0.3 * sa  print ( 'Number of person = ' , no)  print ( 'Sale amount = ' , sa)  print ( 'Comission = ' ,com)  print ( 'Comission + sales = ' ,(sa+com))

Python Program to input any sentence and create a dictionary with consonant and vowels.

name= input ( 'Enter Any Sent.?' ) v_cnt=c_cnt=oth_cnt= 0  vowels= 'aeiou' for i in name :        if i.isalpha ():         if i in vowels :              v_cnt+= 1         else :             c_cnt+= 1    else :          oth_cnt+= 1 print ( v_cnt , c_cnt )  d1= { 'consonant' : c_cnt , 'vowels' : v_cnt , 'Other' : oth_cnt } print ( d1 )

Python program to combine two dictionary adding values for common keys

  d1 = {'a': 100, 'b': 200, 'c':300} d2 = {'a': 300, 'b': 200, 'd':400}  d=dict() for i in d2:     if i in d2:         d[i]=d1[i]+d2[i]     else:         d.update(d1)         d.update(d2) print(d)

Python script to generate and print a dictionary that contains a number (between 1 and n) in the form (number, square of number)

n=int(input('Enter Any number ?'))  d=dict() for i in range(1,n+1):     print(d.update({i:i*i}))

Python script to concatenate following dictionaries to create a new one.

dic1={1:10, 2:20}  dic2={3:30, 4:40} dic3={5:50,6:60} dic1.update(dic2) dic1.update(dic3) d4=dic1 print(d4)

Python Program that reads a string and display it in reverse order.

Str=input('enter any string') l=len(str) a=str[::-1] print(' original string ',Str) print(' reversed string ',a) 

Python Program to input any string and substring and search for substring and print the occurrence of substring in main string if it is there

  # To understand find or search and index function str = input ('Enter any sentence: ') str=str.lower() print (str) ch = input ('Enter character to be found: ') occ= int (input('Enter occurance of character to be found: ') ) c=str.count(ch) if (occ>c):     print ('Not Found') else:     for j in range (len(str)):         i=str[j]         if i==ch:             c-=1         if c==0:             print (occ,'occerance of ',ch,' is at position:',j)             break

Python Program to input any string and differenciat vowels and consonants

  sen=input('Enter a sentence.. ') a=' ' b=' ' for i in sen:   if i in 'aeiou':     a=a+i   elif i==' ':     continue   else:     b=b+i print('vowels=',a,'consonants=',b)

Python Program to input any string and print words starts with consonant and vowels inthe different list

str = input ('Enter any sentence') str+=' ' ns='' vo_word=[] conso_word=[] for ch in str:     if (ch==' '):         c1=ns[0]         if (c1 in 'AEIOUaeiou'):             vo_word.append (ns)         else:             conso_word.append (ns)         ns=''     elif (ch=='.'):         pass     else:         ns+=ch print ('Original string :', str) print ('Vowel words:', vo_word) print ('Consonant words: ',conso_word)

Python Program to input any number(N) and print sum of 1 to N.

n=int(input('Enter Any Number ?')) sum=0 for i in range(1,n+1):     sum=sum+i print(sum)

Python Program to Remove all duplicates from a given string

str = input ("Enter string") len1= len(str) x='' for i in range (len1):     ch = str[i]     if (str.count(ch)==1):         x+=ch print('String after removal of duplicates: ',x)

Python program to print even length words in a string

  str = input ('Enter String') str +=' ' length = len(str) x='' for i in range (length):     ch = str[i]     if (ch!=' '):         x=x+ch     else :         len1 = len(x)         if (len1%2==0):             print (x)         x=''

Python Program to understand length function in python

  str = ' Python Program' x='' c=0 while (x!=str):     c = str[c]      x += ch     c+=1 print (c)

Python Program to Check if a Substring is Present in a Given String

  str = input ('Enter String') word = input ('Enter String to be searched') str +=' ' len = len(str) x='' for i in range (len):     ch = str[i]     if (ch!=' '):         x=x+ch     else :         if (x==word):             print ('Substring is found')             break         x=''

Python program to remove n’th character from string.

  str = input ('Enter string: ') n = int(input ('Enter index to remove character from string: ')) len = len(str) if (n<len):     x=''     for i in range (len):         ch = str[i]         if (n!=i):             x+= ch     print ('New string: ',x)

Python program that accepts a sentence and calculate the number of different type of characters .

  str = input ('Enter string') len = len (str) print ('Length of str = ',len) cu,cc,cd,cs,csd=0,0,0,0,0 for j in range (len):     i=str[j]     if (ord(i)>=65 and ord (i)<=90):         cu+=1     elif (ord(i)>=97 and ord (i)<=122):         cl+=1     elif (i==' '):         cs+=1     elif (ord(i)>=48 and ord (i)<=57):         cd+=1     else :         csd+=1 print ('Upper Case Letters = ', cu) print ('Lower Case Letters = ', cl) print ('Letters = ', cl+cu) print ('Digits = ', cd) print ('Space = ', cs) print ('Special Digits = ', csd) print ('Total length = ', cv+cc+cd+cs+csd)

Python Program that computes the net amount of a bank account based a transaction log from console input.

  #D or d means deposit while W  or w means  withdrawal. bal=0 while('true'):     ch = input ('''Enter d or D for Deposit Enter w or W to Withdraw Enter x to exit ''')     if (ch=='d' or ch == 'D'):         amt = int (input ('Enter amount: '))         bal += amt     elif (ch=='w' or ch == 'W'):         amt = int (input ('Enter amount: '))         bal-= amt     else:         print (bal)         break