Software Development Exam  >  Software Development Notes  >  Basics of Python  >  Code: Number Pattern Solving

Code: Number Pattern Solving | Basics of Python - Software Development PDF Download

1. Write a python program to print following number pattern: 

   1

   2 2

   3 3 3

   4 4 4 4

   5 5 5 5 5

Code:

n=5

for i in range(n):

   for j in range(n):

      print('*', end=' ')

   print()


2. Write a python program to print following pattern: 

  5

  4 4

  3 3 3

  2 2 2 2

  1 1 1 1 1

Code:

n = 5 

for i in range(n): 

   for j in range(i+1): 

      print('*', end=' ')

   print()


3. Write a python code to print following number pattern: 

  0

  2 2

  4 4 4

  6 6 6 6

  8 8 8 8 8

Code:     

n=5

p=0

   for i in range (n):

      for j in range (i+1):

         print (p, end = ' ')

      p+=2

      print()


4. Write a python code to print following pattern: 

  1

  2 2

  1 1 1

  2 2 2 2

  1 1 1 1 1

Code:

n=5

for i in range (n):

  for j in range (i+1):

      if i%2 == 0:

          print ('1', end = ' ')

      else:

          print ('2', end = ' ')

  print()


5. Write a python program to print following Dimond number pattern:

                  1

              2 2 2

          3 3 3 3 3

      4 4 4 4 4 4 4

   5 5 5 5 5 5 5 5 5

      6 6 6 6 6 6 6

          7 7 7 7 7

            8 8 8

                9

Code:

n=5

p=1

for i in range (n-1):

   for j in range (i,n):

      print (' ', end = ' ')

   for j in range (i):

      print (p, end = ' ') 

   for j in range (i+1):

      print (p, end = ' ') 

   p+=1

   print() 

for i in range (n):

   for j in range (i+1):

      print (' ', end = ' ')

   for j in range (i,n-1):

      print (p, end = ' ') 

   for j in range (i,n):

      print (p, end = ' ') 

   p+=1

   print()


6. Write a python program to print following diamond number pattern: 

                  1

               2 2 2

            3 3 3 3 3

        4 4 4 4 4 4 4

     5 5 5 5 5 5 5 5 5

       4 4 4 4 4 4 4

           3 3 3 3 3

              2 2 2

                 1

Code:

n=5

p=1

for i in range (n-1):

    for j in range (i,n):

        print (' ', end = ' ')

    for j in range (i):

        print (p, end = ' ')   

    for j in range (i+1):

        print (p, end = ' ')   

    p+=1

    print()  

for i in range (n):

    for j in range (i+1):

        print (' ', end = ' ')

    for j in range (i,n-1):

        print (p, end = ' ')   

    for j in range (i,n):

        print (p, end = ' ')   

    p-=1

    print()


7. Write a python program to print number pattern: 

   1 

   1 2

   1 2 3

   1 2 3 4

   1 2 3 4 5

Code:

n = 5

for i in range(n):

   p=1

   for j in range(i+1): 

      print(p, end=' ')

      p+=1

   print()


8. Write a python code to print following number pattern: 

  1 2 3 4 5

  1 2 3 4

  1 2 3

  1 2

  1

Code:

n = 5 

   for i in range(n): 

     p=1

     for j in range(i): 

        print(' ', end=' ') 

     for k in range(i, n):

        print(p, end=' ')

        p+=1

     print()


9. Write a python code to print following number hill pattern: 

                1

             1 2 3

          1 2 3 4 5

      1 2 3 4 5 6 7

   1 2 3 4 5 6 7 8 9

Code:

n = 5 

for i in range(n): 

   p=1

   for j in range(i, n): 

      print(' ', end=' ') 

   for j in range(i):

      print(p, end=' ')

      p+=1

   for j in range(i+1):

      print(p, end=' ')

      p+=1

   print(' ')


10. Write a python code to print following number pattern : 

  5

  5 4

  5 4 3

  5 4 3 2

  5 4 3 2 1

Code:

n = 5

for i in range(n):

   p=5

   for j in range(i+1): 

      print(p, end=' ')

      p-=1

   print()


11. Write a python code to print following number pattern : 

  5 4 3 2 1

  4 3 2 1

  3 2 1

  2 1

  1

Code:

n=5

k=5 

for i in range (n):

   p = k

   for j in range (i+1):

      print (' ', end = ' ')

   for j in range (i,n):

      print (p, end = ' ') 

      p-=1

   k-=1

   print()


12. Write a python code to print hill pattern with numbers : 

                1

             1 2 1

          1 2 3 2 1

       1 2 3 4 3 2 1

    1 2 3 4 5 4 3 2 1

Code:

n = 5 

for i in range(n): 

  p=1

  for j in range(i, n): 

     print(' ', end=' ') 

  for j in range(i):

     print(p, end=' ')

     p+=1

  for j in range(i+1):

     print(p, end=' ')

     p-=1

  print()


13. Write a python code to print following number pattern : 

  1

  2 3

  4 5 6

  7 8 9 10

Code:

n = 5

p=1

  for i in range(n):

     for j in range(i+1): 

        print(p, end=' ')

  p+=1

  print()

The document Code: Number Pattern Solving | Basics of Python - Software Development is a part of the Software Development Course Basics of Python.
All you need of Software Development at this link: Software Development
49 videos|38 docs|18 tests

Top Courses for Software Development

49 videos|38 docs|18 tests
Download as PDF
Explore Courses for Software Development exam

Top Courses for Software Development

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Code: Number Pattern Solving | Basics of Python - Software Development

,

shortcuts and tricks

,

Objective type Questions

,

Previous Year Questions with Solutions

,

Viva Questions

,

past year papers

,

MCQs

,

Exam

,

Semester Notes

,

Extra Questions

,

Sample Paper

,

pdf

,

ppt

,

Free

,

Important questions

,

Code: Number Pattern Solving | Basics of Python - Software Development

,

video lectures

,

mock tests for examination

,

Code: Number Pattern Solving | Basics of Python - Software Development

,

study material

,

practice quizzes

,

Summary

;