Question

Python Programming 4th Edition Write a program that calculates the length of a right triangle's hypotenuse....

Python Programming 4th Edition

Write a program that calculates the length of a right triangle's hypotenuse.

Hints:

Define main() program

Get the length of the triangle’s two sides (user input)

Call math function to calculate the length of the hypotenuse.

The output should look like as follows:

The length of the hypotenuse is 12.041594578792296

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import math
# Define main() program
def main():
    # Get the length of the triangle’s two sides (user input)
    side1 = eval(input("Enter length of side1: "))
    side2 = eval(input("Enter length of side2: "))
    # Call math function to calculate the length of the hypotenuse.
    hypotenuse = math.sqrt(math.pow(side1,2)+math.pow(side2,2))
    # The output 
    print("The length of the hypotenuse is",hypotenuse)

# Making call to main() function
main()

Add a comment
Know the answer?
Add Answer to:
Python Programming 4th Edition Write a program that calculates the length of a right triangle's hypotenuse....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python Programming 4th Edition: Write a program that asks the user for the number of feet....

    Python Programming 4th Edition: Write a program that asks the user for the number of feet. The program converts those feet to inches by using the formula ’12 * feet’. Hint: Define main () program Get the number of feet from the user Define variables Call a function feet_to_inches(feet) The function receives the number of feet and returns the number of inches in that many feet. The output should look like as follows: Enter the number of feet: If the...

  • Python Programming 4th Edition: Need help writing this program below. I get an error message that...

    Python Programming 4th Edition: Need help writing this program below. I get an error message that says that name is not defined when running the program below. My solution: def main(): filename = "text.txt" contents=f.read() upper_count=0 lower_count=0 digit_count=0 space_count=0 for i in contents: if i.isupper(): upper_count+=1 elif i.islower(): lower_count+=1 elif i.isdigit(): digit_count+=1 elif i.isspace(): space_count+=1 print("Upper case count in the file is",upper_count) print("Lower case count in the file is",lower_count) print("Digit count in the file is",digit_count) print("Space_count in the file is",space_count)...

  • Starting out with python 4th edition Write program that lets the user enter in a file...

    Starting out with python 4th edition Write program that lets the user enter in a file name (numbers.txt) to read, keeps a running total of how many numbers are in the file, calculates and prints the average of all the numbers in the file. This must use a while loop that ends when end of file is reached. This program should include FileNotFoundError and ValueError exception handling. Sample output: Enter file name: numbers.txt There were 20 numbers in the file....

  • Python Simple Programming Write a program in Python that calculates the tip and total for a...

    Python Simple Programming Write a program in Python that calculates the tip and total for a meal at a restaurant. When your program is run it should ... Calculate the tip and total for a meal for a restaurant Print the name of the application "Tip Calculator" Get input from the user for cost of meal and tip percent Print the tip and total amounts. The formula for calculating the tip amount is: tip = cost of meal * (tip...

  • In this exercise, you will modify the hypotenuse program shown earlier in Figure 9-6. Follow the...

    In this exercise, you will modify the hypotenuse program shown earlier in Figure 9-6. Follow the instructions for starting C++ and viewing the ModifyThis13.cpp file, which is contained in either the Cpp8/Chap09/ModifyThis13 Project folder or the Cpp8/Chap09 folder. Remove both calculation tasks from the main function, and assign both to a program-defined value-returning function named getHypotenuse. Test the program appropriately. //Hypotenuse.cpp - displays the length of a right //triangle's hypotenuse #include <iostream> #include <iomanip> #include <cmath> using namespace std; int...

  • Write Python expressions corresponding to the following statements: The length of the hypotenuse in a right...

    Write Python expressions corresponding to the following statements: The length of the hypotenuse in a right triangle whose other two sides have lengths a and b The value of the expression that evaluates whether the length of the above hypotenuse is 5 The area of a disk of radius a The value of the Boolean expression that checks whether a point with coordinates x and y is inside a circle with center (a, b) and radius r

  • In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a...

    In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a program that asks the user to enter an integer value. Your program will then display that integer back to the user. Your program should include a function called getInteger that requests an integer value from the user and returns that value back to the caller. Your main () function will call the function getInteger and will then display the value returned by that function....

  • #Starting Out With Python, 4th Edition #Chapter 7 #Exercise 6 #in a program, write a function...

    #Starting Out With Python, 4th Edition #Chapter 7 #Exercise 6 #in a program, write a function named roll that #accepts an integer argument number_of_throws. The #function should generate and return a sorted #list of number_of_throws random numbers between #1 and 6. The program should prompt the user to #enter a positive integer that is sent to the function, #and then print the returned list. How would you do this?

  • Write a function PoundsToKilograms that: Takes a number of pounds (an integer) as a parameter, Calculates...

    Write a function PoundsToKilograms that: Takes a number of pounds (an integer) as a parameter, Calculates and returns the corresponding value in kilograms. 1 kilogram is equal to 2.2 pounds. In the main section of the program: Prompt the user to input a weight in pounds, Call the function you wrote to transform the weight into kilograms, Output the weight in kilograms; the number must be shown with 2 decimals after the decimal point. Your program must define and call...

  • 1 // This program will input the value of two sides of a right triangle and...

    1 // This program will input the value of two sides of a right triangle and then 2 // determine the size of the hypotenuse. 3 4 // PLACE YOUR NAME HERE 5 6 #include <iostream> 7 #include <cmath> Il needed for math functions like sqrt() 8 using namespace std; 9 10 int main() 11 { 12 float a, b; // the smaller two sides of the triangle 13 float hyp; // the hypotenuse calculated by the program 14 15...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT