Archive

Posts Tagged ‘Doha-Qatar’

Python project


Python: Draw Flower

Drawing with Python

In this post i tried to draw another flower using arcs of circles, i get a simple one and i guess with more sizes we can do more complex shape.

You can play with the code and change the numbers, size and rotation degree and let’s see what we will have.

t = turtle.Turtle()
t.hideturtle()
t.pendown()
for x in range (30):

t.circle(60,70)

if x %3==0:

t.circle (10,90)

Follow me on Twitter..

Advertisements

Python Project




Python: Binary Search


Binary Search



Definition:

Binary Search is a search algorithm that finds the position of a target value within a sorted array. Binary search compares the target value to the middle element of the array.

In this code we are writing a Python code to find the target in a sorted given array and get its position without using any python math packages.

The case: We have an Array (arr=[2,3,5,6,8,10,11,13,15,16,19]) our target is 13, so we want the position of 13.

We are setting the first position as (pos_s=0) and the end position as (pos_e= the length of the array -1) and we will use recursive function.

Recursive Function: is a computer function or procedure that calling it self


The Code:


arr=[2,3,5,6,8,10,11,13,15,16,19]
target=11
pos_s =0
pos_e=int(len(arr)-1)
midarr =0
def bsearch(arr,target,pos_s,pos_e):

midarr=(pos_s+pos_e)/2

if arr[midarr] < target:

pos_s = midarr +1

bsearch(arr,target,pos_s,pos_e)

elif arr[midarr] > target:

pos_e = midarr -1

bsearch(arr,target,pos_s,pos_e)

elif arr[midarr] == target:

print(‘The target was: ‘,target, ‘ The key of our target is: ‘,midarr)

return

print(arr)
# Call the functin
bsearch(arr,target,pos_s,pos_e)



Follow me on Twitter..

Python : Expenditure App

November 26, 2018 2 comments



Expenditure Application


leveling the Ground:

In this post we will assume that we have a folder for our application, and we will create two files one is for our python code and we will name it “expen.py”, the other is for our data and we will name it “expen_dat.json” this file extension is ‘json’. Also I assume that we have json pack is installed in the PC so if you don’t have json this is the time to install it.

json file:After you create expen_dat.json file just open it with any text editor and copy a test data of our expenditure as shown.

{“expenditure”:
[
{“date”:”02/03/2016″,”amount”:300},
{“date”:”10/04/2016″,”amount”:550},
{“date”:”02/05/2016″,”amount”:300},
{“date”:”10/04/2016″,”amount”:550},
{“date”:”02/03/2016″,”amount”:300},
{“date”:”10/04/2016″,”amount”:550},
{“date”:”05/01/2017″,”amount”:400},
{“date”:”10/02/2017″,”amount”:400},
{“date”:”15/03/2017″,”amount”:400},
{“date”:”20/04/2017″,”amount”:400}
}]

In next post we will start with coding and testing our Expenditure Application.

I will use the @pycharm to write the code and test it, but any other code editors can be used. Also, I assume we have Python and json installed in your PC.

From my Sketch Book




Bird From my Sketch Book

I am sketching to enhance my skill, here is one of sketches from my sketchbook using pencil as a guide-line and ink-pen to finish the drawing.


Click to Enlarge

::My SketchBook::
Sketch of: Bird
Using: Ink-Pen
Date: 5/12/2017
SketchBook: SketchBook # 22
More Sketches: Click Here



Follow me on Twitter..


Inst_icon




Ali,

From my Sketch book




Giraffe From my Sketch Book

I am sketching to enhance my skill, here is one of sketches from my sketchbook using pencil as a guide-line and ink-pen to finish the drawing.


Click to Enlarge

::My SketchBook::
Sketch of: Giraffe
Using: Ink-Pen
Date: 15/10/2017
SketchBook: SketchBook # 22
More Sketches: Click Here



Follow me on Twitter..


Inst_icon




Ali,

From my Sketch Book

March 29, 2018 Leave a comment



Little Sparrow From my Sketch Book

I am sketching to enhance my skill, here is one of sketches from my sketchbook using pencil as a guide-line and ink-pen to finish the drawing.


Click to Enlarge

::My SketchBook::
Sketch of: Little Sparrow
Using: Ink-Pen
Date: 29/12/2017
SketchBook: SketchBook # 23
More Sketches: Click Here



Follow me on Twitter..


Inst_icon




Ali,

From my Sketchbook

March 26, 2018 Leave a comment



Touche Turtle From my Sketch Book

I am sketching to enhance my skill, here is one of sketches from my sketchbook using pencil as a guide-line and ink-pen to finish the drawing.


Click to Enlarge

::My SketchBook::
Sketch of: Touche Turtle
Using: Ink-Pen
Date: 21/1/2017
SketchBook: SketchBook # 13
More Sketches: Click Here



Follow me on Twitter..


Inst_icon




Ali,