Hey guys.
This looks like the right place to ask this question. I just started Python, and I'm still getting familiar with syntaxes and such.

Right now, I'm trying to make a program that will make an Isoceles triangle with Turtle module and math module

I really don't know what else syntax to use without getting errors, but this is what i have so far.

import math
import cTurtle
t = cTurtle.Turtle()
side = "math.acos((BaseLength/2)/SideLength))*(180/3.14159265)"
base = "180-(side*2)"

def IsoTriangle(BaseLength,SideLength,myTurtle):
	myTurtle.forward(BaseLength)
	myTurtle.left(base + 90)
	myTurtle.forward(SideLength)
	myTurtle.left(side + 90)
	myTurtle.forward(SideLength)

can anyone help me fixing up the syntaxes? thanks
(the myTurtle.left(side + 90) might not be right, but all I want is just cTurtle to recognizee the formula so when someone puts the right numbers in, it will draw the triangle)

thanks again

why are you using strings wiht base and side ?
maybe this is something for u

import math
import cTurtle
t = cTurtle.Turtle()
side = math.acos((BaseLength/2)/SideLength))*(180/3.14159265)
base = 180-(side*2)

def IsoTriangle(BaseLength,SideLength,myTurtle):
	myTurtle.forward(BaseLength)
	myTurtle.left(base + 90)
	myTurtle.forward(SideLength)
	myTurtle.left(side + 90)
	myTurtle.forward(SideLength)

Edited 7 Years Ago by Friktion: n/a

if i do that, it says
SyntaxError: invalid syntax (<pyshell#3>, line1)

ok, i fixed that by closing the SideLength with parantheses.

however, it says BaseLength is not defined.
I know it's not ,because the user has to put the numbers themselves in the function so it draws the triangle.

do I have to restructure this? different order?
Please help.

thanks

Edited 7 Years Ago by hkseo100: n/a

I would stay away from module cturtle and use Python's own thoroughly tested module turtle. Here is a small code sample that shows you how to handle the turtle direction properly:

import math
import turtle as tu

base_length = 200
# the two sides are equal in an Isoceles triangle
side_length = 300

# angle shared by base and side
base_angle = math.degrees( math.acos((base_length/2.0)/side_length) )
# angle shared by sides
side_angle = 180 - base_angle*2

# values for speed are 'fastest' (no delay), 'fast', (delay 5ms),
# 'normal' (delay 10ms), 'slow' (delay 15ms), 'slowest' (delay 20ms)
#tu.speed('fastest')

# turtle by default starts at (x=0, y=0) center of display
# to center the triangle lift the pen up then move
# to the left by base_length/2 and down side_length/2 units
# now drop the pen down to start drawing
tu.up()
tu.goto(-base_length/2, -side_length/2)
tu.down()

tu.forward(base_length)
tu.left(180 - base_angle)
tu.forward(side_length)
tu.left(180 - side_angle)
tu.forward(side_length)

# keep showing until corner x is clicked
tu.done()

Edited 7 Years Ago by sneekula: n/a

Oops, DaniWeb is behaving goofy and made two copies of my code!

Edited 7 Years Ago by sneekula: n/a

Hey guys
I got it working, with trial and error,
(sneekula, your code is great too, but sadly I can't use it since my assignment wants me to use cTurtle :-( )

import math
>>> import cTurtle
>>> t = cTurtle.Turtle()
>>> def IsoTriangle(BaseLength,SideLength,myTurtle):
	myTurtle.backward(BaseLength)
	myTurtle.left((math.acos((BaseLength/2)/(SideLength)))*(180/3.14159265))
	myTurtle.forward(SideLength)
	myTurtle.right((math.acos((BaseLength/2)/(SideLength)))*(180/3.14159265)*(2)-(180))
	myTurtle.backward(SideLength)

Edited 7 Years Ago by hkseo100: n/a

This question has already been answered. Start a new discussion instead.