Posts

Showing posts with the label easy python number patterns

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