Python Forum
Lots of code. Creating modules
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lots of code. Creating modules
#1
This is where I am trying to import the module. Having issues and have tried multiple things.
import geometry # my custom input module



rectWidth = ('Enter the Width of rectangle:')
rectLength = ('Enter the length of rectangle:')
radius = ('Enter the radius of circle:')
triangleHeight = ('Enter the Height of triangle:')
triangleBase = ('Enter the Base of triangle:')
xOne = ('Enter the point of X one:')
xTwo = ('Enter the point of X two:')
yOne = ('Enter the point of Y one:')
yTwo = ('Enter the point of Y two:')

finalRectangle = ('{}'.format(calculaterectangle(rectLength,rectWidth)))

print('{:,.2f}'.format (calculaterectangle(rectLength,rectWidth)))
print('{:,.2f}'.format (calculatecircle(radius)))
print('{:,.2f}'.format (calculatetriangle(height,base)))
print('{:,.2f}'.format (calculatdistance(xOne,xTwo,yOne,yTwo)))



THIS IS THE MODULE ITSELF

import math

# Function: calculaterectangle
# Description: This function will calculate the area of a rectangle
# Input: The user is expected to enter length and width
# Output: A message is displayed explaining what is expected from the user.
# Parameters: prompt - message to display to user
# Returns: user's input of sides
def calculaterectangle(rectLength,rectWidth):
rectangleArea = rectLength * rectWidth
return rectangleArea

# Function: calculatecircle
# Description: This function will calculate the area of a circle
# Input: The user is expected to enter radius
# Output: A message is displayed explaining what is expected from the user.
# Parameters: prompt - message to display to user
# Returns: user's input of radius
def calculatecircle(radius):
circlArea = math.pi * radius ** 2
return circleArea

# Function: calculatetriangle
# Description: This function will calculate the area of a right triangle
# Input: The user is expected to enter base and height of triangle
# Output: A message is displayed explaining what is expected from the user.
# Parameters: prompt - message to display to user
# Returns: user's input of base and height
def calculatetriangle(triangleBase,triangleHeight):
triangleArea = triangleBase*triangleHeight/2
return triangleArea

# Function: calculatedistance
# Description: This function will calculate the distance between two points
# Input: The user is expected to enter two coordinates
# Output: A message is displayed explaining what is expected from the user.
# Parameters: prompt - message to display to user
# Returns: user's input of coordinates
def calculatedistance (xOne,xTwo,yOne,yTwo):
distance = math.sqrt((xTwo-xOne)**2 + (yTwo-yOne)**2)
return distance

It is throwing an error on line 37 that said calculaterectangle is not defined
Reply
#2
When you import a module, it has different functions within it. If you look at your usage of the math module, you are using math.sqrt, not just sqrt. You should do the same thing with your imports from the geometry module, like this: geometry.myfunction()

Also, please use code tags next time you post. Just put [python] before the code, and the same thing with /python after it.
Reply
#3
Please write [python] before you paste your code into a post, and then write [/python] after your code is pasted.

(If you prefer, you can paste your code, select it, and then click the python icon in the formatting bar of the post entry dialogue box to enter the start and finish tags for you.)

This will preserve the layout of your code as written in your text editor / IDE, with all the indentations that are critical to python displayed normally.

Without this, the indentations are messed up when you paste code, and we are not as easily able to see where problems might be.
I am trying to help you, really, even if it doesn't always seem that way
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Code: Creating a basic python game? searching1 5 1,876 Nov-12-2018, 05:18 AM
Last Post: searching1
  Creating code to make up to 4 turtle move simultaneously in a random heading J0k3r 3 3,056 Mar-05-2018, 03:48 PM
Last Post: mpd

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020