
from turtle import *
size=800
min=64
pytho=0.8660255 # Pytho = squareroot of 3/2
def triangle(l,x,y):
if l > min:
l=l/2
triangle(l,x,y)
triangle(l,x+l,y)
triangle(l,x+l/2,y+l*pytho)
else:
goto(x,y); pendown()
begin_fill()
forward(l); left(120)
forward(l); left(120)
forward(l)
end_fill()
setheading(0)
penup(); goto(x,y)
penup()
speed('fastest')
triangle(size,-size/2,-size*pytho/2.0)
done()
# code is using recursion
Using python Here is the code import turtle def draw_triangle(vertex, length, k): ''' Draw a ...
Here is a Python program. import turtle class Box: def __init__(self, x, y, width, height): self.x = x self.y = y self.width = width self.height = height def show(self): turtle.up() turtle.goto(x, y) turtle.down() for _ in range(2): turtle.forward(width) turtle.right(90) turtle.forward(height) turtle.right(90) bigbox = Box(-100, -150, 200, 300) bigbox.show() turtle.done() If you run the above program, it will produce an error. What is the keyword that has...
Answer must be in Python 3
Answer:
import turtle
def trifecta(size,angle,num):
for i in range(num):
tri(t,size)
t.right(angle)
t = turtle.Turtle()
s = turtle.Screen()
trifecta(100,25,5)
Question 11 Part b (10 points) Write a function named trifecta() that takes three parameters: 1. size 2. angle 3. num trifecta() should call tri() repeatedly so as to draw num triangles, each with sides of length size. Each triangle should be oriented angle degrees clockwise from the preceding triangle. trifecta() should create a turtle and...
I need help with this code, I have it started here
import sys
import turtle
menu = "Press 1 for Flower"
UserChoice = input(menu)
#function to draw squares
def draw_square(square):
for i in range(0,2):
square.forward(100)
square.right(70)
square.forward(100)
square.right(110)
#function to draw flower
def draw_flower(petalNumber):
window = turtle.Screen()
window.bgcolor("yellow")
pen = turtle.Turtle()
pen.shape("triangle")
pen.color("red")
for number in range(0,petalNumber):
draw_square(pen)
pen.right(360/petalNumber)
for i in range(0,4):
pen.circle(20)
pen.right(90)
pen.right(90)
pen.forward(300)
pen.right(90)
draw_square(pen)
pen.left(180)
draw_square(pen)
pen.left(270)
pen.forward(200)
window.exitonclick()
#function for original art...
I cannot run this code! Please explain and fix it for me import turtle import random # Approximate size of turtle objects in pixels BODY_SIZE = 80 # Half if the body size for collision detection with the edge of the screen HALF_BODY_SIZE = BODY_SIZE / 2 # if enemies get this close to friend there is collision COLLISION_DISTANCE = 5 # The window size SIZE = 500 # inner boundary within window for reversing the direction of enemies LOWER_BOUND...
dle Edit Search View Encoding Language Settings Tools Macro Run Plugins Window 1 isport turtle 3 tina turtle.Turtle 4 SCreen-turtle.Screen ) 5 acreen.bgoolor ("white") 6 tina.shape ("turtle" 7tina.pencolor ("blue") SCALE -20 10 12 13 14 15 16 17 18 19 20 21 input: n # output: a drawing of n concentric circles centered at 0,0 # this function is written using iteration (using a loop) Edef concentric loop (n) : for size in range(n) : tina.penup tina goto (O, -SCALE...
import random import turtle def isInScreen(win,turt): leftBound = -win.window_width() / 2 rightBound = win.window_width() / 2 topBound = win.window_height() / 2 bottomBound = -win.window_height() / 2 turtleX = turt.xcor() turtleY = turt.ycor() stillIn = True if turtleX > rightBound or turtleX < leftBound: stillIn = False if turtleY > topBound or turtleY < bottomBound: stillIn = False return stillIn def main(): wn = turtle.Screen() # Define your turtles here june = turtle.Turtle() june.shape('turtle') while isInScreen(wn,june): coin = random.randrange(0, 2) if...
Python. Just work in the def sierpinski. No output needed. Will
give thumbs up for any attempt beginning this code.
Your task is to implement this algorithm in Python, returning a random collection of inum-100, 000 points. You should then plot the points to see the structure. Please complete the following function: def sierpinski (po, v, f, inum) The four arguments are ·po the initial point. You may assume this is the origin, i.e., po = [0, 0] . v:...
11p
Python Language
Read the following code for oofraction. import oofraction class OOFraction: def main(): fl = oofraction.o0Fraction( 2, 5) f2 = oofraction.o0Fraction ( 1, 3) f3 = f1 + f2 print (str(3)) main() def __init__(self, Num, Den): self.mNum = Num self.mDen = Den return def_add_(self,other): num = self.mNumother.mDen + other.mNum*self.mDen den = self.mDen*other.mDen f = OOFraction(num,den) return f 1. Write the output below. def_str_(self): s = str( self.mNum )+"/" + str( self.mDen) returns 2. Write a class called wholeNum...
I need help with my python class. thanks! Question 12 Code Example 4-4 main program: import arithmetic as a def multiply(num1, num2): product = num1 * num2 result = a.add(product, product) return result def main(): num1 = 4 num2 = 3 answer = multiply(num1, num2) print("The answer is", answer) if __name__ == "__main__": main() arithmetic module: def add(x, y): z = x + y return z Refer to Code...
convert the following code from python to java.
def topkFrequent(nums, k): if not nums: return [ ] if len(nums) == 1: return nums [0] # first find freq freq dict d = {} for num in nums: if num in d: d[num] -= 1 # reverse the sign on the freq for the heap's sake else: d[num] = -1 h = [] from heapq import heappush, heappop for key in di heappush(h, (d[key], key)) res = [] count = 0...