Python Programming: An Introduction to Computer Science, 3rd Ed.
3rd Edition
ISBN: 9781590282755
Author: John Zelle
Publisher: Franklin, Beedle & Associates
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 3, Problem 9PE
Program Plan Intro
Area of a triangle
Program Plan:
- Define the main function.
- Get the values of “a”, “b”, and “c” from the user.
- Calculate perimeter of the triangle and store it in a variable “s”.
- Calculate area of a triangle and store it in a variable “area”.
- Print the value of “area”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Using Heron's formula, you can calculate the area of a triangle if you know the lengths of all three sides. Given the length of each side of a triangle as input, calculate the area of the triangle using Heron's formula as follows:
s = half of the triangle's perimeter
area = the square root of s(s-a)(s-b)(s-c), where a, b, and c are each sides of the triangle.
Use the Math.sqrt() method for calculating the square root.
Output the floating-point value of the area with three digits after the decimal point, which can be achieved as follows:System.out.printf("The area of the triangle is %.3f\n", yourValue);
You can calculate the area of a triangle if you know the lengths of all three sides, using a
formula that has been known for nearly 2000 years. It is called "Heron's Formula". Heron's formula
uses the following two steps to calculate the area of a triangle.
Step 1: Calculate "s" (half of the triangles perimeter): S=
Step 2: Calculate Area: A = √s(sa)(sb)(sc)
By using Heron's formula, write the definition of the function area_of_triangle so that it can work in
conjunction with the following source code.
#include
#include
int main (void)
{
double a, b, c, area;
printf("Enter the sides of triangle\n");
scanf("%lf%lf%lf", &a, &b, &c);
a+b+c
2
area = area_of_triangle (a, b, c);
printf ("Area of triangle = %.21f\n", area);
return 0;
}
You can use sqrt() from math.h header file. Its prototype is: double sqrt (double x);
A sample run of this program is shown in the following figure.
Enter the sides of triangle
4.0
5.0
6.0
Area of triangle = 9.92
The Harris-Benedict equation estimates the number of calories your body needs to maintainyour weight if you do no exercise. This is called your basal metabolic rate, or BMR.The formula for the calories needed for a woman to maintain her weight isBMR = 655 + (4.3 x weight in pounds) + (4.7 x height in inches) -(4.7 x age in years)The formula for the calories needed for a man to maintain his weight isBMR = 66 + (6.3 x weight in pounds) + (12.9 x height in inches) -(6.8 x age in years)A typical chocolate bar will contain around 230 calories. Write a program that allows the userto input his or her weight in pounds, height in inches, age in years, and the character M formale and F for female. The program should then output the number of chocolate bars thatshould be consumed to maintain one's weight for the appropriate sex of the specified weight,height, and age.
Chapter 3 Solutions
Python Programming: An Introduction to Computer Science, 3rd Ed.
Ch. 3 - Prob. 1TFCh. 3 - Prob. 2TFCh. 3 - Prob. 3TFCh. 3 - Prob. 4TFCh. 3 - Prob. 5TFCh. 3 - Prob. 6TFCh. 3 - Prob. 7TFCh. 3 - Prob. 8TFCh. 3 - Prob. 9TFCh. 3 - Prob. 10TF
Ch. 3 - Prob. 1MCCh. 3 - Prob. 2MCCh. 3 - Prob. 3MCCh. 3 - Prob. 4MCCh. 3 - Prob. 5MCCh. 3 - Prob. 6MCCh. 3 - Prob. 7MCCh. 3 - Prob. 8MCCh. 3 - Prob. 9MCCh. 3 - Prob. 10MCCh. 3 - Prob. 1DCh. 3 - Prob. 3DCh. 3 - Prob. 4DCh. 3 - Prob. 6DCh. 3 - Prob. 1PECh. 3 - Prob. 2PECh. 3 - Prob. 3PECh. 3 - Prob. 4PECh. 3 - Prob. 5PECh. 3 - Prob. 6PECh. 3 - Prob. 7PECh. 3 - Prob. 8PECh. 3 - Prob. 9PECh. 3 - Prob. 10PECh. 3 - Prob. 11PECh. 3 - Prob. 12PECh. 3 - Prob. 13PECh. 3 - Prob. 14PECh. 3 - Prob. 15PECh. 3 - Prob. 16PECh. 3 - Prob. 17PE
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- (Mechanics) The deflection at any point along the centerline of a cantilevered beam, such as the one used for a balcony (see Figure 5.15), when a load is distributed evenly along the beam is given by this formula: d=wx224EI(x2+6l24lx) d is the deflection at location x (ft). xisthedistancefromthesecuredend( ft).wistheweightplacedattheendofthebeam( lbs/ft).listhebeamlength( ft). Eisthemodulesofelasticity( lbs/f t 2 ).Iisthesecondmomentofinertia( f t 4 ). For the beam shown in Figure 5.15, the second moment of inertia is determined as follows: l=bh312 b is the beam’s base. h is the beam’s height. Using these formulas, write, compile, and run a C++ program that determines and displays a table of the deflection for a cantilevered pine beam at half-foot increments along its length, using the following data: w=200lbs/ftl=3ftE=187.2106lb/ft2b=.2fth=.3ftarrow_forwardThe Harris-Benedict equation estimates the number of calories your body needs to maintain your weight if you do no exercise. This is called your basal metabolic rate, or BMR. The calories needed for a woman to maintain her weight is: WBMR = 655 + (4.3 × weight in pounds) + (4.7 × height in inches) − (4.7× age in years) The calories needed for a man to maintain his weight is: MBMR = 66 + (6.3 × weight in pounds) + (12.9 × height in inches) − (6.8 × age in years) A typical chocolate bar will contain around 230 calories. Write a java program that allows the user to input his or her weight in pounds, height in inches, and age in years. The program should then output the number of chocolate bars that should be consumed to maintain one’s weight for both a woman and a man of the input weight, height, and age. NOTE: This is an application of a selection statement! Input Data: Use a named constant for the number of calories in a “typical chocolate bar.” Use Scanner methods to enter the…arrow_forwardUsing Heron's formula, you can calculate the area of a triangle if you know the lengths of all three sides. Given the length of each side of a triangle as input, calculate the area of the triangle using Heron's formula as follows: s = half of the triangle's perimeter area = the square root of s(s-a)(s-b)(s-c), where a, b, and c are each sides of the triangle. Hint: Use the sqrt() function from the math module to calculate the square root. Output the floating-point value of the area with three digits after the decimal point, which can be achieved as follows:print('The area of the triangle is: {:.3f}'.format(your_value)) Ex: If the input for a, b, and c is: 3.0 4.0 5.0 the output is: The area of the triangle is: 6.000arrow_forward
- A typical NMR peak after Fourier transform has a Lorentzian absorptive line shape. This line shape is represented by the function below, where x is in Hz 1 f (x) : x2 + 1 Write a program to calculate the integral of this function using Riemann sums on the range from [-10, 10] (inclusive) with dx = 0.01. In other words, estimate the following integral with a Riemann sum. 10 1 x2 + 1 -10arrow_forwardAerospace engineers sometimes compute the trajectories of projectiles such as rockets. A related problem deals with the trajectory of a thrown ball. The trajectory of a thrown by a right fielder is defined by the (x,y) coordinates as displayed in the Figure below. Find the appropriate initial angle θ0 , if v0 = 30m/s, and the distance to the catcher is 90 m. Note that the throw leaves the right fielder’s hand at an elevation of 1.8 m and the catcher receives it at 1 m. Also, you have to write your Matlab code.arrow_forwardCreate a c ++programarrow_forward
- Write a program that converts degree Kelvin(TK) to degrees Fahrenheit (TF)arrow_forwardThe programming language is Python Using the unit functions " math "find the result of the following equation √x y = sin(x) x 4 cos(x) Write a program to create the following figurearrow_forwardWrite a C language program to read base and height of a rectangle then compute and display the area using the formula given AREA = BASE * HEIGHTarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Constants, Variables, Data types, Keywords in C Programming Language Tutorial; Author: LearningLad;https://www.youtube.com/watch?v=d7tdL-ZEWdE;License: Standard YouTube License, CC-BY