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()


Replace multiple words

test_str = 'Python for engineers,The complete solution for python programs'

print("The original string is : " + str(test_str))

word_list = ["for", 'The', 'solution']

repl_wrd = 'hai'

res = ' '.join([repl_wrd if idx in word_list else idx for idx in test_str.split()])

print("String after multiple replace : " + str(res))


Program for Counting Sort

def countSort(arr):

output = [0 for i in range(256)]

count = [0 for i in range(256)]

ans = ["" for _ in arr]

for i in arr:

count[ord(i)] += 1

for i in range(256):

count[i] += count[i-1]

for i in range(len(arr)):

output[count[ord(arr[i])]-1] = arr[i]

count[ord(arr[i])] -= 1

for i in range(len(arr)):

ans[i] = output[i]

return ans

arr = "Pythonforengineers"

ans = countSort(arr)

print ("Sorted character array is %s" %("".join(ans)))