Oct-07-2016, 04:00 PM
So my issue is this we have started using functions and the module we are supposed to import does not import its from a zip file for examples from the book they all run fine when they are opened by themselves but when trying to import them into another program I get no response. Also I have tried multiple OS's downloading the examples file a few times but the same error occurs no matter what. The files also have read and write permissions.
This is the module that needs to be imported
Syntax Error: import UsefulTurtleFunctions from drawLine:
- Compute Angles Redux. Name the program computeAnglesRedux.py. Write a new version of the ComputeAngles.py program, on pages 66-67, in which you use functions to (i) draw the triangle with the coordinates input by the user, and (ii) abstract the calculations out of the main program into functions, thus creating a program that is easier to understand and maintain.
Your program shall:
- Define and use the function distance([b]xa, ya, xb, yb)[/b], which returns the distance between the points (xa, ya) and (xb, yb). (This calculation is already in ComputeAngles.py --see lines 5-7)
- Define and use the function determineAngle([b]p, q, r)[/b], which returns the angle in degrees opposite to side p of the triangle. (This calculation is already in ComputeAngles.py --see lines 9-11).
This function returns the result, in degrees, of evaluating the formula:
cos−1(p2−q2−r2)−2qr
- Define and use the function distance([b]xa, ya, xb, yb)[/b], which returns the distance between the points (xa, ya) and (xb, yb). (This calculation is already in ComputeAngles.py --see lines 5-7)
This is the module that needs to be imported
import turtle # Draw a line from (x1, y1) to (x2, y2) def drawLine(x1, y1, x2, y2): turtle.penup() turtle.goto(x1, y1) turtle.pendown() turtle.goto(x2, y2) # Write a text at the specified location (x, y) def writeText(s, x, y): turtle.penup() # Pull the pen up turtle.goto(x, y) turtle.pendown() # Pull the pen down turtle.write(s) # Write a string # Draw a point at the specified location (x, y) def drawPoint(x, y): turtle.penup() # Pull the pen up turtle.goto(x, y) turtle.pendown() # Pull the pen down turtle.begin_fill() # Begin to fill color in a shape turtle.circle(3) turtle.end_fill() # Fill the shape # Draw a circle at centered at (x, y) with the specified radius def drawCircle(x, y, radius): turtle.penup() # Pull the pen up turtle.goto(x, y - radius) turtle.pendown() # Pull the pen down turtle.circle(radius) # Draw a rectangle at (x, y) with the specified width and height def drawRectangle(x, y, width, height): turtle.penup() # Pull the pen up turtle.goto(x + width / 2, y + height / 2) turtle.pendown() # Pull the pen down turtle.right(90) turtle.forward(height) turtle.right(90) turtle.forward(width) turtle.right(90) turtle.forward(height) turtle.right(90) turtle.forward(width)And here is the problem we are supposed to recreate using functions
import math x1, y1, x2, y2, x3, y3 = eval(input("Enter six coordinates of three points \ separated by commas like x1, y1, x2, y2, x3, y3: ")) a = math.sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3)) b = math.sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3)) c = math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) A = math.degrees(math.acos((a * a - b * b - c * c) / (-2 * b * c))) B = math.degrees(math.acos((b * b - a * a - c * c) / (-2 * a * c))) C = math.degrees(math.acos((c * c - b * b - a * a) / (-2 * a * b))) print("The three angles are ", round(A * 100) / 100.0, round(B * 100) / 100.0, round(C * 100) / 100.0)Here is the error I get every single time
Syntax Error: import UsefulTurtleFunctions from drawLine: