Stooge Sort

def stoogesort(arr, l, h):

if l >= h:

return

if arr[l]>arr[h]:

t = arr[l]

arr[l] = arr[h]

arr[h] = t

if h-l + 1 > 2:

t = (int)((h-l + 1)/3)

stoogesort(arr, l, (h-t))

stoogesort(arr, l + t, (h))

stoogesort(arr, l, (h-t))

arr = [2, 4, 5, 3, 1]

n = len(arr)

stoogesort(arr, 0, n-1)

for i in range(0, n):

print(arr[i], end = ' ')


checking the given number is Lucky or Not

import math

def isLucky(n):

ar = [0] * 10

while (n > 0):

digit = math.floor(n % 10)

if (ar[digit]):

return 0

ar[digit] = 1

n = n / 10

return 1

arr = [1291, 897, 4566, 1232, 80, 700]

n = len(arr)

for i in range(0, n):

k = arr[i]

if(isLucky(k)):

print(k, " is Lucky ")

else:

print(k, " is not Lucky ")


Google Drive Logo Using Turtle

import turtle as t

t.hideturtle()

t.Screen().bgcolor("Black")

t.pencolor("white")

t.pensize(0)

t.begin_fill()

t.fillcolor('#4688F4')

t.forward(170)

t.left(60)

t.forward(50)

t.left(120)

t.forward(220)

t.left(120)

t.forward(50)

t.end_fill()

t.begin_fill()

t.fillcolor('#1FA463')

t.left(120)

t.forward(200)

t.left(120)

t.forward(50)

t.left(60)

t.forward(150)

t.left(60)

t.forward(50)

t.end_fill()

t.penup()

t.left(120)

t.forward(200)

t.left(120)

t.forward(50)

t.pendown()

t.begin_fill()

t.fillcolor('#FFD048')

t.left(125)

t.forward(160)

t.left(55)

t.forward(53)

t.left(126)

t.forward(163)

t.end_fill()

t.done()


Check whether a string starts and ends with the same character or not (using Regular Expression)

import re

regex = r'^[a-z]$|^([a-z]).*\1$'

def check(string):

if(re.search(regex, string)):

print("Valid")

else:

print("Invalid")

if __name__ == '__main__' :


sample1 = "abba"

sample2 = "a"

sample3 = "abcd"


check(sample1)

check(sample2)

check(sample3)


Javascript logo using turtle

import turtle

t=turtle.Turtle()

t.penup()

t.goto(-20,-70)

t.color("#F0DB4F","#F0DB4F")

t.begin_fill()

t.pendown()

t.left(165)

t.forward(100)

t.right(70)

t.forward(220)

t.setheading(0)

t.forward(229)

t.penup()

t.goto(-20,-70)

t.setheading(0)

t.pendown()

t.left(15)

t.forward(100)

t.left(70)

t.forward(229)

t.end_fill()

t.penup()

t.goto(-35,-20)

t.setheading(90)

t.color("white","white")

t.pendown()

t.begin_fill()

t.forward(150)

t.left(90)

t.forward(20)

t.left(90)

t.forward(130)

t.setheading(90)

t.left(75)

t.forward(40)

t.left(110)

t.forward(20)


t.penup()

t.goto(-35,-20)

t.setheading(90)

t.left(75)

t.pendown()

t.forward(60)

t.end_fill()

t.penup()

t.color("yellow","yellow")

t.goto(-20,-55)

t.setheading(90)

t.pendown()

t.begin_fill()

t.forward(215)

t.right(90)

t.forward(100)

t.right(95)

t.forward(195)

t.left(90)

t.end_fill()

t.penup()

t.color("white","white")

t.pensize(2)

t.goto(-10,-20)

t.begin_fill()

t.setheading(0)

t.left(15)

t.pendown()

t.forward(65)

t.left(70)

t.forward(70)

t.left(90)

t.left(15)

t.forward(50)

t.right(100)

t.forward(50)

t.right(90)

t.forward(50)

t.left(85)

t.forward(20)

t.left(95)

t.forward(70)

t.left(90)

t.forward(90)

t.left(100)

t.forward(50)

t.right(105)

t.forward(37)

t.right(75)

t.forward(50)

t.left(85)

t.forward(20)

t.end_fill()

t.hideturtle()

turtle.done()