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]),