Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python 3 Exercise 8. Triangles Write a function is_valid(s1, s2, s3) that takes three floating point numbers as arguments and returns a boolean indicating whether

image text in transcribed

Python 3

Exercise 8. Triangles Write a function is_valid(s1, s2, s3) that takes three floating point numbers as arguments and returns a boolean indicating whether or not these numbers can be the lengths of the sides of a valid triangle. The input is valid if the sum of any two sides is greater than the third side. Write a function area(s1, s2, 53) that returns the area of a triangle given the lengths of its three sides. The area of a triangle whose sides are s1, s2, and s3 is sqrt(s(s - 51)(s - s2)(s - s3)) where s = (51 +52 +53)/2. Write a program triangle.py that takes three floating point numbers as command line arguments and checks whether these numbers can be the lengths of the sides of a valid triangle. If the input is valid the program should also compute and print the area of the triangle. > python triangle.py 3.7 4.2 2.5 Valid triangle. Area is 4.589117562233507 > python triangle.py 2.7 5.2 1.3 Invalid triangle. Exercise 9. Substrings. Write a function substring(s1, s2, k) that takes two strings and an integer index k, and returns True if the first string appears as a substring in the second starting at location k, and False otherwise. You may assume that all strings consist of lowercase characters only. Write a function how many() that takes two strings and returns the number of times the first string occurs in the second. Again, you may assume that all strings consist of lowercase characters only. For example, the call how many("bob", "azcbobobegghaki") should return 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_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions