Question

Write a python program that calculates the area of triangle. The user will be asked to...

Write a python program that calculates the area of triangle. The user will be asked to enter the base (b) and the height (h). The formula to calculate the area is:

Triangle_area=(bh)/2

Note: the program should print the area to the user: (for example: the area of the triangle is: 34.3)

Homework Answers

Answer #1

As per question, we need to take two input from user. First is height of the triangle and second is base. For that we need to create two variables.

Then we need to cast the user input value into float. So, that program will throw an error when user try to enter string value.

After that we need to create a area variable which will store the result of   formula for calculating the area.

Now, we need to print the result. So, inside the print function we need to use format mathod to show the result as per requirement.

var_height = float(input("Enter the height of triangle: "))
var_base = float(input("Enter the base of triangle: "))

var_area = var_height*var_base*0.5
print("The area of triangle is: {}".format(var_area))

Know the answer?
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
Similar Questions
Write a Python program to calculate the area of a circle. The user needs to input...
Write a Python program to calculate the area of a circle. The user needs to input the value of the radius of the circle. area = 3.14 x radius x radius You should use a function named circlearea to perform the calculation 3. Write a Python program to calculate the area of a square. The user needs to input the value of the length of the square. area = len*len You should use a function named squarearea to perform the...
Write code in JAVA Write a program that will output a right triangle based on user...
Write code in JAVA Write a program that will output a right triangle based on user specified input height (int) and specified input symbol (char).The first line will have one user-specified character, such as % or *. Each subsequent line will have one additional user-specified character until the number in the triangle's base reaches specified input height. Output a space after each user-specified character, including after the line's last user-specified character. Hint: Use a nested for loop. Ex:If the input...
Write a Python program which calculates the average of the numbers entered by the user through...
Write a Python program which calculates the average of the numbers entered by the user through the keyboard. Use an interactive loop and ask the user at each iteration if he/she wants to enter more numbers. At the end dispay the average on the screen. Using built-in library functions for finding average is not allowed. Sample output of the program: Enter a number > 23 More numbers (yes or no)? y Enter a number > 4 Do you have more...
Write a C++ program with a user-defined function myFactorial, that calculates the factorial of a number...
Write a C++ program with a user-defined function myFactorial, that calculates the factorial of a number entered by the user. Return the calculated factorial and print it in the main function.
Write a Python program that will ask the user to enter the masses of two particles...
Write a Python program that will ask the user to enter the masses of two particles (particle one and particle two) and particle 1’s initial velocity (v1). Assume particle two is at rest. The program should calculate the scattering angle and velocity for particle 2 as a function of the scattering angle and resulting velocity of particle 1
Write a program that prompts the user for the number of values for which it will...
Write a program that prompts the user for the number of values for which it will calculate the base 2 log of each value. Use a for loop to iterate the set of values and print the log for each. Here is the formula to change the base of a log: loga b = log10 b / log10 a Sample output appears below. This program will calculate the Base 2 log of a set of numbers<LINERETURN> ===============================================================<LINERETURN> Enter the upper...
Write a program in python to display all the consonant in the user input. E.g. user...
Write a program in python to display all the consonant in the user input. E.g. user input: Hello Good Day to you. Output: consonant H = 1 consonant l = 2 consonant G = 1   consonant d = 1 consonant D = 1 etc
Covert the following Java program to a Python program: import java.util.Scanner; /* Calculates and displays the...
Covert the following Java program to a Python program: import java.util.Scanner; /* Calculates and displays the area of a rectangle * based on the width and length entered by the user. */ public class RectangleArea2 {             public static void main(String[] args) { int length; //longer side of rectangle             int width; //shorter side of rectangle int area; //calculated area of rectangle Scanner input = new Scanner(System.in);                               System.out.print("Enter the length: ");            length = input.nextInt(); System.out.print("Enter...
IN PYTHON : Write a program that asks the user for a number. Write the number...
IN PYTHON : Write a program that asks the user for a number. Write the number to a file called total.txt. Then ask the user for a second number. Write the new number on line 2 with the total for both numbers next to it separated by a comma. Then ask the user for a third number and do the same. Keep asking for numbers until the person puts in a zero to terminate the program. Close the file. Be...
Question 1 Write a program that reads from the user the height and radius of a...
Question 1 Write a program that reads from the user the height and radius of a cylinder, and then outputs the area of this cylinder. The area of the cylinder is calculated using the formula: A=2*π*r*h+2*π*r2, where π = 3.14. Sample run: Enter the radius of the cylinder: 8.2 Enter the height of the cylinder: 9 The area of the cylinder is 885.75 Question 2 Write a program that reads the name, weight and height of a patient. Then the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT