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


Program for Radix Sort

def countingSort(arr, exp1):

n = len(arr)

output = [0] * (n)

count = [0] * (10)

for i in range(0, n):

index = (arr[i]/exp1)

count[int((index)%10)] += 1

for i in range(1,10):

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

i = n-1

while i>=0:

index = (arr[i]/exp1)

output[ count[ int((index)%10) ] - 1] = arr[i]

count[int((index)%10)] -= 1

i -= 1

i = 0

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

arr[i] = output[i]

def radixSort(arr):

max1 = max(arr)

exp = 1

while max1/exp > 0:

countingSort(arr,exp)

exp *= 10

arr = [ 170, 45, 75, 90, 802, 24, 2, 66]

radixSort(arr)

for i in range(len(arr)):

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


Maximum profit by buying and selling a share at most k times

def maxProfit(prices, n, k):

profit = [[0 for i in range(k + 1)]

for j in range(n)]

for i in range(1, n):

for j in range(1, k + 1):

max_so_far = 0

for l in range(i):

max_so_far = max(max_so_far, prices[i] -

prices[l] + profit[l][j - 1])

profit[i][j] = max(profit[i - 1][j], max_so_far)

return profit[n - 1][k]

k = 2

prices = [10, 22, 5, 75, 65, 80]

n = len(prices)

print("Maximum profit is:",

maxProfit(prices, n, k))