Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Both 4 and 5 please. Please have explanations beside every code. Question 4: Heron's Formula (3 points) Given a triangle with sides a, b, and

Both 4 and 5 please. Please have explanations beside every code.image text in transcribedimage text in transcribed

Question 4: Heron's Formula (3 points) Given a triangle with sides a, b, and c, compute its area using Heron's formula. For this, see the Wikipedia page at http://en.wikipedia.org /wiki/Heron%27s_formula. The formula makes use of square roots. Consult https://docs.python.org/3/ to find out how to use square roots in Python. In [ ]: from math import sqrt def heron(a, b, c): # your code here! return ans In [ ]: assert (heron (15,20,25) == 150) In [ ]: assert (round (heron(1,1,sqrt(2)),1) == 0.5) #Sidenote for the curious: round() is a built-in python function for rounding out floating points to zero or specified It should not be required for your solution to this question. Question 5: Quadratic Formula (3 points) In Python, it is possible to return multiple values/variables in one return expression, as shown below. Use this fact to compute and return both solutions to the quadratic formula, -b + V62 4ac X1, X2 = = 2a 2a_ Write a program that takes a, b, and c as input and solves for X1 and X2. You may assume that b2 4ac > 0. Let x1 be the solution where you add the term under the square root term, and x2 be the solution where you subtract the square root term. In [ ]: from math import sqrt def quadratic(a, b, c): # Your code here. return (x1, x2) In [ ]: assert (quadratic(1,7,12) == (-3.0,-4.0) or quadratic(1,7,12) == (-4.0,-3.0)) In [ ]: assert (quadratic(5,6,1) == (-0.2,-1.0) or quadratic(5,6,1) == (-1.0,-0.2))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Next Generation Databases NoSQLand Big Data

Authors: Guy Harrison

1st Edition

1484213300, 978-1484213308

More Books

Students also viewed these Databases questions

Question

What were some of the team roles at Casper?

Answered: 1 week ago

Question

What were some of the team norms at Casper?

Answered: 1 week ago