Question
1. Exercise 5.1 If you are given three sticks, you may or may not be able to arrange them in a triangle. For example, if
1. Exercise 5.1
If you are given three sticks, you may or may not be able to arrange them in a triangle. For example, if one of the sticks is 12 inches long and the other two are one inch long, you will not be able to get the short sticks to meet in the middle. For any three lengths, there is a simple test to see if it is possible to form a triangle:
If any of the three lengths is greater than the sum of the other two, then you cannot form a triangle. Otherwise, you can. (If the sum of two lengths equals the third, they form what is called a degenerate triangle.)
-
Write a function named is_triangle that takes three integers as arguments. The function should return True or False to report whether or not the three sticks can make a triangle.
-
From main(), call the is_triangle function and pass it three integer values representing the length of three sticks. If the returned value of the is_triangle function is True, print Yes to the screen. Otherwise, print No to the screen.
Test Your Function
Two tests appear here for you to use. Use these buttons to test your code:
Should return No
TRY IT (STICK LENGTHS 1, 1, AND 12)
Should return Yes
TRY IT (STICK LENGTHS 12, 16, AND 24)
Submit For Grading
Once you have tested your code, submit it here for grading.
Exercise 5.1
Make sure the response you print to the screen is either Yes or No (the capitalization is important.)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2. Exercise 5.2
A bike share program in Indianapolis allows customers to borrow a bike and charge them based on the length of their ride.
The program offers two memberships: Daily or Annual.
For Daily members, rides cost 1.50 to start + .20/minute.
For Annual members, rides cost 1.00 to start + .15/minute.
-
Write a function named calculate_fee that takes a string and an integer as arguments and returns the calculated fee with no dollar signs or rounding based on the users membership level.
-
From main(), call the calculate_fee function and pass both the string and integer values. The function should calculate the fee based on the membership level. Print the returned value of the calculate_fee function to the screen with no dollar signs or rounding (Do not forget the 1.50/1.00 start ride fee!)
Test Your Function
Two tests appear here for you to use. Use these buttons to test your code:
Should return the float 5.5
TRY IT (DAILY MEMBER TAKES A 20 MINUTE TRIP)
Should return the float 3.25
TRY IT (ANNUAL MEMBER TAKES A 15 MINUTE TRIP)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3. Exercise 5.3
A persons Body Mass Index is a common measure of their fitness (whether we like it or not.)
The BMI calculation in the English system is:
((weight_in_pounds) / (height_in_inches * height_in_inches)) * 703
BMI Categories:
- Underweight = <18.5
- Normal = 18.524.9
- Overweight = 2529.9
- Obese = BMI >= 30
-
Write a function named calculate_bmi that takes two floats as arguments and returns the calculated BMI rounded to 1 decimal place based on the users weight and height.
-
From main(), call the calculate_bmi function and pass both float values. Use the returned value of the function to determine and print the BMI Category the user falls into.
Printed Values
Your program MUST print exactly one of the following:
- Underweight
- Normal
- Overweight
- Obese
Capitalization is important!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started