Side look emoji using turtle

import turtle

my_pen = turtle.Turtle()


my_pen.color("#ffdd00")

my_pen.begin_fill()

my_pen.circle(100)

my_pen.fillcolor("#ffdd00")

my_pen.end_fill()

my_pen.home()


my_pen.goto(-40, 100)

my_pen.color("#555555")

my_pen.begin_fill()

my_pen.circle(15)

my_pen.color("#ffffff")

my_pen.end_fill()

my_pen.penup()

my_pen.goto(-48, 110)

my_pen.pendown()

my_pen.color("Black")

my_pen.begin_fill()

my_pen.circle(5)

my_pen.end_fill()

my_pen.penup()


my_pen.goto(40, 100)

my_pen.pendown()

my_pen.color("#555555")

my_pen.begin_fill()

my_pen.circle(15)

my_pen.color("#ffffff")

my_pen.end_fill()

my_pen.penup()

my_pen.goto(32, 110)

my_pen.pendown()

my_pen.color("Black")

my_pen.begin_fill()

my_pen.circle(5)

my_pen.end_fill()

my_pen.penup()


my_pen.goto(-20, 50)

my_pen.pendown()

my_pen.pensize(10)

my_pen.forward(40)


turtle.done()

Legendre's Conjecture program

import math

def isprime( n ):

i = 2

for i in range (2, int((math.sqrt(n)+1))):

if n%i == 0:

return False

return True

def LegendreConjecture( n ):

print ( "Primes in the range ", n*n

, " and ", (n+1)*(n+1)

, " are:" )

for i in range (n*n, (((n+1)*(n+1))+1)):

if(isprime(i)):

print (i)

n = 50

LegendreConjecture(n)



A clock dial using turtle

import turtle

screen=turtle.Screen()

trtl=turtle.Turtle()

screen.setup(620,620)

screen.bgcolor('black')

clr=['red','green','blue','yellow','purple']

trtl.pensize(4)

trtl.shape('turtle')

trtl.penup()

trtl.pencolor('red')

m=0

for i in range(12):

      m=m+1

      trtl.penup()

      trtl.setheading(-30*i+60)

      trtl.forward(150)

      trtl.pendown()

      trtl.forward(25)

      trtl.penup()

      trtl.forward(20)

      trtl.write(str(m),align="center",font=("Arial", 12, "normal"))

      if m==12:

        m=0

      trtl.home()

trtl.home()

trtl.setpos(0,-250)

trtl.pendown()

trtl.pensize(10)

trtl.pencolor('blue')

trtl.circle(250)

trtl.penup()

trtl.setpos(150,-270)

trtl.pendown()

trtl.ht()

Printing anagrams together using List and Dictionary

def allAnagram(input):

dict = {}

for strVal in input:

key = ''.join(sorted(strVal))

if key in dict.keys():

dict[key].append(strVal)

else:

dict[key] = []

dict[key].append(strVal)

output = ""

for key,value in dict.items():

output = output + ' '.join(value) + ' '

return output

if __name__ == "__main__":

input=['cat', 'dog', 'tac', 'god', 'act']

print (allAnagram(input))


Program for Reversal algorithm for array rotation

def rverseArray(arr, start, end):

while (start < end):

temp = arr[start]

arr[start] = arr[end]

arr[end] = temp

start += 1

end = end-1

def leftRotate(arr, d):

n = len(arr)

rverseArray(arr, 0, d-1)

rverseArray(arr, d, n-1)

rverseArray(arr, 0, n-1)

def printArray(arr):

for i in range(0, len(arr)):

print (arr[i])

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

leftRotate(arr, 2)

printArray(arr)


Program to Split the array and add the first part to the end

def splitArr(arr, n, k):

for i in range(0, k):

x = arr[0]

for j in range(0, n-1):

arr[j] = arr[j + 1]

arr[n-1] = x

arr = [12, 8, 10, 11, 52, 36]

n = len(arr)

position = 2

splitArr(arr, n, position)

for i in range(0, n):

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


Program for BogoSort or Permutation Sort

import random

def bogoSort(a):

n = len(a)

while (is_sorted(a)== False):

shuffle(a)

def is_sorted(a):

n = len(a)

for i in range(0, n-1):

if (a[i] > a[i+1] ):

return False

return True

def shuffle(a):

n = len(a)

for i in range (0,n):

r = random.randint(0,n-1)

a[i], a[r] = a[r], a[i]

a = [3, 2, 4, 1, 0, 5]

bogoSort(a)

print("Sorted array :")

for i in range(len(a)):

print ("%d" %a[i]),


Program to find mirror characters in a string

def mirrorChars(input,k):

original = 'abcdefghijklmnopqrstuvwxyz'

reverse = 'zyxwvutsrqponmlkjihgfedcba'

dictChars = dict(zip(original,reverse))

prefix = input[0:k-1]

suffix = input[k-1:]

mirror = ''

for i in range(0,len(suffix)):

mirror = mirror + dictChars[suffix[i]]

print (prefix+mirror)

if __name__ == "__main__":

input = 'paradox'

k = 3

mirrorChars(input,k)


Turtle race using python

import turtle

from random import *

from turtle import *

penup()

goto(-140,140)

for sp in range(15): 

  write(sp)

  right(90)

  forward(10)

  pendown()

  forward(150)

  penup()

  backward(160)

  left(90)

  forward(20)

x = Turtle() 

x.color('green') 

x.shape('turtle') 

x.penup() 

x.goto(-160,100) 

x.pendown() 

y = Turtle() 

y.color('red') 

y.shape('turtle') 

y.penup() 

y.goto(-160,80) 

y.pendown() 

turtlee = Turtle() 

turtlee.color('blue') 

turtlee.shape('turtle') 

turtlee.penup() 

turtlee.goto(-160,60) 

turtlee.pendown() 

for turn in range(100): 

  x.forward(randint(1,5)) 

  y.forward(randint(1,5)) 

  turtlee.forward(randint(1,5)) 

turtle.done()

Program for Recursive Topological Sorting

from collections import defaultdict

class Graph:

def __init__(self,vertices):

self.graph = defaultdict(list) 

self.V = vertices 

def addEdge(self,u,v):

self.graph[u].append(v)

def topologicalSortUtil(self,v,visited,stack):

visited[v] = True

for i in self.graph[v]:

if visited[i] == False:

self.topologicalSortUtil(i,visited,stack)

stack.insert(0,v)

def topologicalSort(self):

visited = [False]*self.V

stack =[]

for i in range(self.V):

if visited[i] == False:

self.topologicalSortUtil(i,visited,stack)

print (stack)

g= Graph(6)

g.addEdge(5, 2);

g.addEdge(5, 0);

g.addEdge(4, 0);

g.addEdge(4, 1);

g.addEdge(2, 3);

g.addEdge(3, 1);

print ("Following is a Topological Sort of the given graph")

g.topologicalSort()