Home.Verilog.Digital Design.Digital Basics.Python.RF Basics.
Previous.
Next.
Custom Search

Feedback ? Send it to admin@fullchipdesign.com or join me at fullchip@gmail.com

Legal Disclaimer

Chip Designing for ASIC/ FPGA Design engineers and Students
FULLCHIPDESIGN
Digital-logic Design...  Dream for many students… start learning front-end…
Try navigation bar on top to explore the contents @ fullchipdesign

Legal Disclaimer

Custom Search
File read operations.

Class & global var.

File write op's.

Glob module.

Conditional stms.

String 2 hex.

UNIX in Python.

Diamond Pattern.

TypeError - arg.

TyprError - str.

TypeError - strconv.

AttributeError.

Function call.

Read bin files.

 

# import python modules

import sys

import os

import string

 

# Declare number of lines to be read this value should be odd

line = 15    

print "print %s" % (line)

 

# Calculate centre of the diamond, also calculate the offset  

centre = line/2

offset = line - 2*centre

 

if offset == 0:

        print "...Error the number of lines should be odd"

        sys.exit()

 

if offset == 1:

    centre = centre + 1

 

# Print statements

print "centre %s" %(centre)

print "--Here in the diamond for lines = %s--" % (line)

 

# Generate the diamond pattern

 

# Calculate spaces and stars for each line  

 

for line_d in range (1,line+1,1):

    spaces = centre - line_d

    if spaces < 0:

        spaces = spaces * -1

    stars = 2*(centre - spaces) - 1    

   diamond = ""

    for l in range (0, spaces, 1):

           diamond = diamond + " "    

    for q in range (0, stars, 1):

           diamond = diamond + "*"

    print diamond

 

 

      *********

     ***********

   *************

  ***************

   *************

    ***********

     *********

      *******

       *****

        ***

         *

Python code to print a diamond pattern.

           *

          ***

        *****

       *******