Drawing a H-Tree Fractal using turtle in python program


import turtle
SPEED = 8
BG_COLOR = "red"
PEN_COLOR = "lightgreen"
SCREEN_WIDTH = 600
SCREEN_HEIGHT = 600
DRAWING_WIDTH = 500
DRAWING_HEIGHT = 500
PEN_WIDTH = 5
TITLE = "H-Tree Fractal"
FRACTAL_DEPTH = 3
def draw_line(tur, pos1, pos2):
    tur.penup()
    tur.goto(pos1[0], pos1[1])
    tur.pendown()
    tur.goto(pos2[0], pos2[1])

def recursive_draw(tur, x, y, width, height, count):
    draw_line(
        tur,
        [x + width * 0.25, height // 2 + y],
        [x + width * 0.75, height // 2 + y],
    )
    draw_line(
        tur,
        [x + width * 0.25, (height * 0.5) // 2 + y],
        [x + width * 0.25, (height * 1.5) // 2 + y],
    )
    draw_line(
        tur,
        [x + width * 0.75, (height * 0.5) // 2 + y],
        [x + width * 0.75, (height * 1.5) // 2 + y],
    )
    if count <= 0: 
        return
    else: 
        count -= 1
    
        recursive_draw(tur, x, y, width // 2, height // 2, count)
        recursive_draw(tur, x + width // 2, y, width // 2, height // 2, count)
       recursive_draw(tur, x, y + width // 2, width // 2, height // 2, count)
       recursive_draw(tur, x + width // 2, y + width // 2, width // 2, height // 2, count)

if __name__ == "__main__":
    # Screen setup
    screen = turtle.Screen()
    screen.setup(SCREEN_WIDTH, SCREEN_HEIGHT)
    screen.title(TITLE)
    screen.bgcolor(BG_COLOR)
    # Turtle artist (pen) setup
    artist = turtle.Turtle()
    artist.hideturtle()
    artist.pensize(PEN_WIDTH)
    artist.color(PEN_COLOR)
    artist.speed(SPEED)
   
    recursive_draw(artist, - DRAWING_WIDTH / 2, - DRAWING_HEIGHT / 2, DRAWING_WIDTH, DRAWING_HEIGHT, FRACTAL_DEPTH)
   
    turtle.done()

Drawing a fractal tree using turtle in python program


 import turtle
MINIMUM_BRANCH_LENGTH = 15
def build_tree(t, branch_length, shorten_by, angle):
  if branch_length > MINIMUM_BRANCH_LENGTH:
    t.forward(branch_length)
    new_length = branch_length - shorten_by
    t.left(angle)
    build_tree(t, new_length, shorten_by, angle)
    t.right(angle * 2)
    build_tree(t, new_length, shorten_by, angle)
    t.left(angle)
    t.backward(branch_length)
tree = turtle.Turtle()
tree.hideturtle()
tree.setheading(90)
tree.color('red')
build_tree(tree, 50, 5, 30)
turtle.mainloop()

Biopython - Python Tools for Computational Molecular Biology


Biopython is a set of freely available tools for biological computation written in Python by an international team of developers.

HUGO - The world’s fastest framework for building websites

Hugo is one of the most popular open-source static site generators. With its amazing speed and flexibility, Hugo makes building websites fun again.

Hugo Features

Hugo boasts blistering speed, robust content management, and a powerful templating language making it a great fit for all kinds of static websites.

General 

Extremely fast build times (< 1 ms per page)

Completely cross platform, with easy installation on macOS, Linux, Windows, and more

Renders changes on the fly with LiveReload as you develop

Powerful theming

Host your site anywhere

Organization 

Straightforward organization for your projects, including website sections

Customizable URLs

Support for configurable taxonomies, including categories and tags

Sort content as you desire through powerful template functions

Automatic table of contents generation

Dynamic menu creation

Pretty URLs support

Permalink pattern support

Redirects via aliases

Content 

Native Markdown and Emacs Org-Mode support, as well as other languages via external helpers (see supported formats)

TOML, YAML, and JSON metadata support in front matter

Customizable homepage

Multiple content types

Automatic and user defined content summaries

Shortcodes to enable rich content inside of Markdown

“Minutes to Read” functionality

“WordCount” functionality

Additional Features 

Integrated Disqus comment support

Integrated Google Analytics support

Automatic RSS creation

Support for Go HTML templates

Syntax highlighting powered by Chroma

Python Arithmetic Operators - An Review

I was well versed in python programming.

One morning a question was shooted at me by one of the blog followers

What is the output of   6/2 , 6//2 , 6%2

I was able to provide the answer for 6%2 as zero, but confused to answer 6/2 and 6//2 

/ Division              # Provide floating point as output 

// Floor division      #Rounds the result down to the nearest whole number

% Modulus              # Remainder 

Python named TIOBE’s programming language of 2020




Python has won the TIOBE programming language of the year award! This is for the fourth time in the history, which is a record! The title is awarded to the programming language that has gained most popularity in one year. Python made a positive jump of 2.01% in 2020. Programming language C++ is a very close runner up with an increase of 1.99%. Other winners are C (+1.66%), Groovy (+1.23%) and R (+1.10%).

More Details


Python Programming for Blood Bank Management System

import MySQLdb
from Tkinter import *
from PIL import Image
db=MySQLdb.connect("localhost","root","pswd","bbms")
cursor=db.cursor()
root = Tk()
image1=PhotoImage(file="/home/aishwarya/Downloads/bg.gif")
panel=Label(root,image=image1,bg="black").place(x=0,y=0,relwidth=1,relheight=1)
root.title("BLOOD BANK")
root.geometry("1920x1080")
root.configure(background='white')
l3=Label(root,text="BLOOD BANK SYSTEM",bg='white',font = "Helvetica 15 bold").place(x=450,y=40,w=300,h=40)
l1=Label(root,text="Click to enter the details of the donor",bg='white',font="Helvetica 12").place(x=80,y=100,w=300,h=40)
b1=Button(root,text="Donor Details",command=lambda : donordetails()).place(x=80,y=150)
l2=Label(root,text="Click to enter the details of the blood",bg='white',font="Helvetica 12").place(x=80,y=200,w=300,h=40)
b2=Button(root,text="Blood Details",command=lambda : blooddetails()).place(x=80,y=250)
l3=Label(root,text="Click to make a request for blood",bg='white',font="Helvetica 12").place(x=80,y=300,w=300,h=40)
b3=Button(root,text="Blood Request",command=lambda : requestblood()).place(x=80,y=350)
b2=Button(root,text="Exit",command=lambda : stop(root)).place(x=80,y=400)
v = StringVar()
def insertDonor(name,age,gender,address,contactno):
insert = "INSERT INTO donors(name,age,gender,address,contactno) VALUES('"+name+"','"+age+"','"+gender+"','"+address+"',"+"'"+contactno+"')"
try:
cursor.execute(insert)
db.commit()
except:
db.rollback()
def insertBlood(bloodgroup,platelet,rbc):
insert= "INSERT INTO blood(bloodgroup,platelet,rbc,date) VALUES('"+bloodgroup+"',"+"'"+platelet+"',"+"'"+rbc+"',"+"CURDATE())"
try:
cursor.execute(insert)
db.commit()
except:
db.rollback()
def retrieve(bg):
request="select * from donors inner join blood using(id) where bloodgroup='"+bg+"'"
try:
cursor.execute(request)
rows=cursor.fetchall()
db.commit()
print (len(rows))
return rows
except:
db.rollback() 
def sel():
   selection = "You selected the option " + v.get()
   print (selection)
def donordetails():
#global v
root=Toplevel()
root.title("BLOOD BANK")
root.geometry("1024x768")
root.configure(background ='#FF8F8F')
l1=Label(root,text="Name:",bg='white',font="Helvetica 12").place(x=40,y=40)
l2=Label(root,text="Age:",bg='white',font="Helvetica 12").place(x=40,y=80)
l3=Label(root,text="Gender:",bg='white',font="Helvetica 12").place(x=40,y=120)
l4=Label(root,text="Address:",bg='white',font="Helvetica 12").place(x=40,y=220)
l5=Label(root,text="Contact:",bg='white',font="Helvetica 12").place(x=40,y=260)
e1=Entry(root)
e1.place(x=120,y=40)
e2=Entry(root)
e2.place(x=120,y=80)
r1=Radiobutton(root,text="Male",variable=v,value="Male",command=sel).place(x=120,y=120)
r2=Radiobutton(root,text="Female",variable=v,value="Female",command=sel).place(x=120,y=150)
r3=Radiobutton(root,text="Other",variable=v,value="Other",command=sel).place(x=120,y=180)
e4=Entry(root)
e4.place(x=120,y=220)
e5=Entry(root)
e5.place(x=120,y=260)
root.mainloop()
def blooddetails():
root=Tk()
root.title("BLOOD BANK")
root.geometry("1024x768")
root.configure(background ='#FF8F8F')
l1=Label(root,text="Blood Group:",font="Helvetica 12").place(x=40,y=40,w=250,h=20)
l2=Label(root,text="PLatetelet count (in 100 thousands):",font="Helvetica 12").place(x=40,y=80,w=250,h=20)
l3=Label(root,text="RBC count (in millions):",font="Helvetica 12").place(x=40,y=120,w=250,h=20)
e1=Entry(root)
e1.place(x=350,y=40)
e2=Entry(root)
e2.place(x=350,y=80)
e3=Entry(root)
e3.place(x=350,y=120)
b2=Button(root,text="Back",command=lambda : stop(root)).place(x=200,y=160)
b1=Button(root,text="Submit",command=lambda : insertBlood(e1.get(),e2.get(),e3.get())).place(x=40,y=160)
root.mainloop()
def grid1(bg):
root=Tk()
root.title("LIST OF MATCHING DONORS")
root.geometry("750x500")
root.configure(background='#0C43F0')
rows=retrieve(bg)
x=0
for row in rows:
l1=Label(root,text=row[0],bg="#1EDEF2",font = "Verdana 15 bold").grid(row=x,column=0,sticky='E',padx=5,pady=5,ipadx=5,ipady=5)
l2=Label(root,text=row[1],bg="#1EDEF2",font = "Verdana 15 bold").grid(row=x,column=1,sticky='E',padx=5,pady=5,ipadx=5,ipady=5)
l3=Label(root,text=row[2],bg="#1EDEF2",font = "Verdana 15 bold").grid(row=x,column=2,sticky='E',padx=5,pady=5,ipadx=5,ipady=5)
l4=Label(root,text=row[3],bg="#1EDEF2",font = "Verdana 15 bold").grid(row=x,column=3,sticky='E',padx=5,pady=5,ipadx=5,ipady=5)
l5=Label(root,text=row[4],bg="#1EDEF2",font = "Verdana 15 bold").grid(row=x,column=4,sticky='E',padx=5,pady=5,ipadx=5,ipady=5)
l6=Label(root,text=row[5],bg="#1EDEF2",font = "Verdana 15 bold").grid(row=x,column=5,sticky='E',padx=5,pady=5,ipadx=5,ipady=5)
l7=Label(root,text=row[6],bg="#1EDEF2",font = "Verdana 15 bold").grid(row=x,column=6,sticky='E',padx=5,pady=5,ipadx=5,ipady=5)
l8=Label(root,text=row[7],bg="#1EDEF2",font = "Verdana 15 bold").grid(row=x,column=7,sticky='E',padx=5,pady=5,ipadx=5,ipady=5)
l9=Label(root,text=row[8],bg="#1EDEF2",font = "Verdana 15 bold").grid(row=x,column=8,sticky='E',padx=5,pady=5,ipadx=5,ipady=5)
l10=Label(root,text=row[9],bg="#1EDEF2",font = "Verdana 15 bold").grid(row=x,column=9,sticky='E',padx=5,pady=5,ipadx=5,ipady=5)
x=x+1
root.mainloop()
def requestblood():
root=Tk()
root.title("BLOOD BANK")
root.geometry("1024x720")
root.configure(background='#FF8F8F')
l=Label(root,text="Enter the blood group").place(x=50,y=50,w=400,h=40)
e=Entry(root)
e.place(x=500,y=50)
b2=Button(root,text="Back",command=lambda : stop(root)).place(x=600,y=100)
b=Button(root,text="ENTER",command=lambda : grid1(e.get())).place(x=500,y=100)
root.mainloop()
def stop(root):
root.destroy()
root.mainloop()