Posts

Showing posts with the label coding written exam questions

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 ...

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): ...

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')