[Tutor] tutoring

Angel Abad angeltheabad at gmail.com
Tue Nov 26 13:57:46 EST 2019


hello, i was wondering if i could get help with my homework?

this is the examples that was given in class that i don't seem to
understand how to do.

###TODO 1: Convert this to a function that takes a string as ###input
### (i.e., the string to print, "Welcome..." in this example)
### and prints the string with the border.  The function should
### not return anything.  (Optional: take the border character to print
### and the # of characters, e.g., = and 50 in this example)
print("=" * 50)
print("Welcome to the GeoCalc program!")
print("=" * 50)
### END TODO 1

print()


###TODO 2: Convert this to a function that takes the square side length
### as input, and returns the calculated area of the square.
### Save the value returned from the function in firstSquareArea
firstSquareArea = squareSide ** 2
### END TODO 2

squareSideString = input("Please enter the side length for your 2nd square: ")

while not squareSideString.isdigit():
    squareSideString = input("Please enter the side length for your
2nd square: ")

squareSide = int(squareSideString)

###TODO 3: use your function from TODO 2 here.
### Save the value returned from the function in secondSquareArea
secondSquareArea = squareSide ** 2
### END TODO 3

triangleBaseString = input("Please enter the base for your 1st triangle: ")

while not triangleBaseString.isdigit():
    triangleBaseString = input("Please enter the base for your 1st triangle: ")

triangleHeightString = input("Please enter the height for your 1st triangle: ")

while not triangleHeightString.isdigit():
    triangleHeightString = input("Please enter the height for your 1st
triangle: ")

triangleBase = float(triangleBaseString)
triangleHeight = float(triangleHeightString)

###TODO 4: Convert this to a function that takes the triangle base AND height
### as inputs, and returns the calculated area of the triangle.
### Save the value returned from the function in firstTriangleArea
firstTriangleArea = 1/2 * triangleBase * triangleHeight
### END TODO 4

triangleBaseString = input("Please enter the base for your 2nd triangle: ")

while not triangleBaseString.isdigit():
    triangleBaseString = input("Please enter the base for your 2nd triangle: ")

triangleHeightString = input("Please enter the height for your 2nd triangle: ")

while not triangleHeightString.isdigit():
    triangleHeightString = input("Please enter the height for your 2nd
triangle: ")

triangleBase = float(triangleBaseString)
triangleHeight = float(triangleHeightString)

###TODO 5: use your function from TODO 4 here.
### Save the value returned from the function in secondTriangleArea
secondTriangleArea = 1/2 * triangleBase * triangleHeight
### END TODO 5

#Print the results
print()
print("Your first square area is:", firstSquareArea)
print("Your second square area is:", secondSquareArea)
print("Your first triangle area is:", firstTriangleArea)
print("Your second triangle area is:", secondTriangleArea)
print()

###TODO 6: Use your function from TODO 1 to print this message with border.
print("=" * 50)
print("Goodbye, thank you for using the GeoCalc program!")
print("=" * 50)
### END TODO 6

thank you,

angel


More information about the Tutor mailing list