Posts

Multiple ways of taking input in python

There are a multiple ways to take input. In most of the coding problems,we have to take input in different formats. Let's see some of the formats now. To take integer input: x=int(input()) Values are integers,if we print x value,x will be printed as integer value. To take float input,that is decimal values like 5.5,0.5,-0.6 etc . x=float(input()) we can also give integer values as input like 5,-5 etc.But if we print x,it will print them in float values i.e. 5.0,-0.5,-0.6 To take string input,i.e. characters or sentences. x=input() inputs like p,python,python is best. Take n number of  integer inputs one after another . n=int(input()) for i in range(n):     x=int(input()) Take n number of float inputs one after another. n=int(input()) for i in range(n):     x=float(input()) Take n number of string inputs one after another. n=int(input()) for i in range(n):     x=input() Take unknown number of integer inputs  at a time,in a single line separated by sp

Alphabet patterns in python

problem 1: sample input:5 sample output: A B C D E F G H I J K L M N O python code: import string x=string.ascii_uppercase k=0 n=int(input()) for i in range(n):     for j in range(i+1):         print(x[k],end=' ')         k+=1     print('\r')    problem 2: sample input:5 sample output: a b c d e f g h i j k l m n o python code: import string x=string.ascii_lowercase k=0 n=int(input()) for i in range(n):     for j in range(i+1):         print(x[k],end=' ')         k+=1     print('\r') problem 3: sample input:5 sample output: A B B C C C D D D D E E E E E python code: import string x=string.ascii_uppercase k=0 n=int(input()) for i in range(n):     for j in range(i+1):         print(x[k],end=' ')     k+=1     print('\r')      problem 4: sample input:5 sample output: a b b c c c d d d d e e e e e python code: import string x=string.ascii_lowercase k=0 n=int(input()

Number patterns in python

As we all know,python is an easy  to start programming language. Patterns are the most problems given in hiring interviews. So,lets get started fully on number patterns. problem 1 : print the following pattern. sample input 1:            5 sample output 1: 1 2 4 4 8 8 8 16 16 16 16 32 32 32 32 sample input 2: 3 sample output 2: 1 2 4 4 8 8 python code: n=int(input()) k=1 for i in range(0,n):     for j in range(0,i+1):         if j>=1:             print(k,end=' ')         elif j<2:             print(k,end=' ')             k=k*2     print('\n')  problem 2: sample input :4 sample output: 1 3 2 6 5 4 10 9 8 7 python code: n=int(input()) k=1 for i in range(n):     l=[]     h=''     for j in range(i+1):         l.append(str(k))         k+=1     l.reverse()     h=' '.join(l)     print(h)     print('\r')        problem 3: sample input:4 sample output: 1 2 1 4 2 1

whether a word is palindrome or not using functions

As we all know,python is an easy  to start programming language. coding programs are the most problems given in hiring interviews. So,lets get started basic programs. problem: Find out whether a given word is palindrome or not. sample input: madam sample output: palindrome python code: def palin(word):     if len(word)<2:         return True     if word[0]==word[-1]:         return palin(word[1:-1])     else:         return False n=input() result=palin(n) if(result):     print('palindrome') else:     print('not palindrome')

fibonacci series using function

As we all know,python is an easy  to start programming language. coding program are the most problems given in hiring interviews. So,lets get started with basic programs. problem :find the nth element in fibonacci series. sample input:7 sample output:13 python code: def fib(n):     if(n==0):         return 0     elif(n==1):         return 1     else:         return fib(n-1)+fib(n-2) n=int(input('enter an integer value')) for i in range(0,n+1):     x=fib(i) print(x) 

star patterns in python

As we all know,python is an easy  to start programming language. Patterns are the most problems given in hiring interviews. So,lets get started fully on patterns. problem 1: For an input number 'n',print right angle triangle of n columns in '*'. sample input:5 sample output: * * * * * * * * * * * * * * * python code: n=int(input()) for i in range(n):     for j in range(0,i+1):         print('* ',end='')     print('\n') problem 2: sample input:5 sample output: * * * * * * * * * * * * * * * * * * * * * * * * * python code: n=int(input('enter integer input\n')) for i in range(1,n+1):     print('* '*(2*i-1)) problem 3: sample input:5 sample output: *       *   *   *      *      *   *  *       * python code: n=int(input()) for i in range(0,n):     for j in range(n):         if(i==j or i+j==n-1):             print('*',end=' ')         else:             print(' '

python code for FLAMES

Python code for Flames As a human,I always wants to know what others feel about me.In my childhood,my friends and I used to find flames with our crushes. So,I thought that it would be good,if we can show our crush how much we love her..by writing code for FLAMES. So,here's the basic code for finding FLAMES using python. As we all know,Flames is for friendship,love,attraction,marriage,engagement,soulmate. Python Code: def hell(l,m):     del m[l-1]     if len(m)==1:         l=k         return l,m     else:         m=m[l-1:]+m[0:l-1]         l=k         return l,m def dus(l,m):     if l<=len(m):         l,m=hell(l,m)         if len(m)==1:             print(t[m[0]])                     else:             dus(l,m)             else:         l=l-len(m)         dus(l,m) m=['F','L','A','M','E','S'] a=input('Enter the name of your crush in small letters\n') b=input('Enter your name in small