Question

In: Computer Science

#Write a function called solve_right_triangle. The function #solve_right_triangle should have three parameters: opposite, #adjacent, and use_degrees....

#Write a function called solve_right_triangle. The function
#solve_right_triangle should have three parameters: opposite,
#adjacent, and use_degrees. opposite and adjacent will be
#floats, and use_degrees will be a boolean. use_degrees
#should be a keyword parameter, and it should have a
#default value of False.
#
#The function should return a tuple containing the
#hypotenuse and angle of the right triangle (in that order).
#If use_degrees is False, the angle should be in radians.
#If use_degrees is True, the angle should be in degrees.
#
#Remember, the formula for the hypotenuse of a right
#triangle is the square root of the sum of the squared side
#lengths. You can find arctan using math.atan(), passing in
#the quotient of the opposite and adjacent as the argument.
#By default, math.atan() returns the angle in radians; you
#can pass that angle as an argument into the math.degrees()
#method to convert it to degrees; for example:
#
# angle_in_degrees = math.degrees(angle_in_radians)

import math

Solutions

Expert Solution

# Write a function called solve_right_triangle. The function
# solve_right_triangle should have three parameters: opposite,
# adjacent, and use_degrees. opposite and adjacent will be
# floats, and use_degrees will be a boolean. use_degrees
# should be a keyword parameter, and it should have a
# default value of False.
#
# The function should return a tuple containing the
# hypotenuse and angle of the right triangle (in that order).
# If use_degrees is False, the angle should be in radians.
# If use_degrees is True, the angle should be in degrees.
#
# Remember, the formula for the hypotenuse of a right
# triangle is the square root of the sum of the squared side
# lengths. You can find arctan using math.atan(), passing in
# the quotient of the opposite and adjacent as the argument.
# By default, math.atan() returns the angle in radians; you
# can pass that angle as an argument into the math.degrees()
# method to convert it to degrees; for example:
#
# angle_in_degrees = math.degrees(angle_in_radians)

import math


def solve_right_triangle(opposite, adjacent, use_degrees=False):
    hypotenuse = math.sqrt(opposite * opposite + adjacent * adjacent)
    angle = math.atan(opposite / adjacent)
    if use_degrees:
        angle = math.degrees(angle)
    return hypotenuse, angle

Related Solutions

#Write a function called wish_list. wish_list should have #four parameters, in this order: # # -...
#Write a function called wish_list. wish_list should have #four parameters, in this order: # # - a list of strings, representing a list of items on a # wish list # - a string, representing a particular item # - a float, representing the cost of this item # - a float, representing your budget # #If the item is on the list and you can afford it (cost is #less than or equal to budget), return the string, #"You...
Write a Matlab function called: lin_interp. The function should have three inputs: the two original data...
Write a Matlab function called: lin_interp. The function should have three inputs: the two original data arrays (call them x and f), and the array you would like to interpolate to (call it xstar). The function should have one output: the interpolated array ( call it fstar). The function should be able to interpolate x and f onto xstar using linear interpolation and give the result as fstar. The function may not use any intrinsic functions except length.
using python 1. #Write a function called multiply_file_by_index. This function #should take two parameters, both strings....
using python 1. #Write a function called multiply_file_by_index. This function #should take two parameters, both strings. The first string is #the filename of a file to which to write (output_file), and #the second string is the filename of a file from which to read #(input_file). # #In the input file, there will be an integer on every line. #To the output file, you should write the integer from the #original file multiplied by the line number on which it #appeared....
Write a function called fillList that takes three parameters, an integer array, input file, and size....
Write a function called fillList that takes three parameters, an integer array, input file, and size. The function should fill the integer array with randomly generated values between two numbers lowLim and highLim read from the input file. in C++
Write an overloaded function of function area with 3 (float) parameters. This function should calculate and...
Write an overloaded function of function area with 3 (float) parameters. This function should calculate and print out the product of the 3 parameters.
C++ Write the definition of a function minMax that has five parameters. The first three parameters...
C++ Write the definition of a function minMax that has five parameters. The first three parameters are integers. The last two are set by the function to the largest and smallest of the values of the first three parameters. The function does not return a value. The function can be used as follows: int a=31, b=5, c=19 big, small; minMax(a,b,c,&big,&small); /* big is now 31 */ /* small is now 5 */ **ONLY THE FUNCTION
Write a function in c++, called afterAll that takes two parameters, a vector of string and...
Write a function in c++, called afterAll that takes two parameters, a vector of string and a string. The function returns true if the 2nd parameter comes after all of the strings in the vector, order-wise, false if not. As an example, "zoo" comes after "yuzu".
Write a function called price_of_rocks. It has no parameters. In a while loop, get a rock...
Write a function called price_of_rocks. It has no parameters. In a while loop, get a rock type and a weight from the user. Keep a running total of the price for all requested rocks. Repeat until the user wants to quit. Quartz crystals cost $23 per pound. Garnets cost $160 per pound. Meteorite costs $15.50 per gram. Assume the user enters weights in the units as above. Return the total price of all of the material. Using Python For this...
This is an intro to python question. #Write a function called search_for_string() that takes two #parameters,...
This is an intro to python question. #Write a function called search_for_string() that takes two #parameters, a list of strings, and a string. This function #should return a list of all the indices at which the #string is found within the list. # #You may assume that you do not need to search inside the #items in the list; for examples: # # search_for_string(["bob", "burgers", "tina", "bob"], "bob") # -> [0,3] # search_for_string(["bob", "burgers", "tina", "bob"], "bae") # -> []...
Write a function in R named counts. This function should take as parameters a numeric vector...
Write a function in R named counts. This function should take as parameters a numeric vector x and also a number indicating a number of bins n. The function will consider the range [min(x),max(x)], and then consider a parti- tion of this interval into n non-overlapping equally sized half open intervals: I1 = [min(x),b1),I2 = [b1,b − 2),...,In = (bn−1,max(x)]. Note that since the intervals are equally sized, the value of bi is constrained. The function will then return a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT