Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

BLOCKPY 29.1-29.5 nested if statements practice IN PYTHON First Last )M #29.2) Possibly Undefined #293) Animal Rater #29.4) Stay Positive #29.5) Redundant lf Server. Saved

BLOCKPY 29.1-29.5 nested if statements practice IN PYTHON

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

First Last )M #29.2) Possibly Undefined #293) Animal Rater #29.4) Stay Positive #29.5) Redundant lf Server. Saved BlockPy: #29.1) Drinking Function Create a function named can_drink that takes in age and has_license. Then, use your logic from question #27.2 as the function's body. Change the function's body to return strings (not print!). Call the function with your own information (again, or make it up) and print the result of calling it. Ready Here is the logic from #272: if you are 21 or older if you are less than 1000 years old if you have a license then return "Can drink" otherwise then return "Doesn't have a license" otherwise then return "Too old" otherwise the return "Too young" 5000: tax - .9 return salary *tax 5 print (calculate_income (1000)) 6 print (calculate_income (10000)) #29.5) Redundant lf Server Saved Execution: Idle BlockPy: #29.3) Animal Rater Create a function named rate_animal that will rate the value of animals on a numeric scale (1-4, where 1 is best and 4 is worst). Your function should consume a variable (holding a string value) named an_animal and return an integer from 1-4 for each of four possible inputs: "dog","cat", "capybara" and "danger noodle". Each animal should have its own value. If the string given is not a valid animal from the list, return -1.Call and print the function once with your favorite animal. Console Feedback: Ready Run 1: Blocks Split Text Reset O Upload History #29.4) Stay Positive #295) Redundant if Server Loaded Execution BlockPy: #29.4) Stay Positive Create a function named add_positives that consumes two numbers and returns their sum. However, if either number is less than zero, you should instead return 0. Call the function twice. Idle Console Feedback: Ready Run 1: Blocks Split Text Reset O Upload History 2 #29.5) Redundant If Saved BlockPy: #295) Redundant lf The code below uses an unnecessary if/else statement. Refactor the code (modify it without changing its behavior) so that it no longer uses an if/else statement. Server Execution Idle Console False True Feedback: Instructor Feedback You should refactor the code so that it no longer uses an if statement. Run BlocksSplitTextResetUpload History 1 def am_i_on fire(temperature): if (temperature > 109True: return True else: return False 6 print (am_i_on fire(100)) 7 print (am_i_on fire(110))

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

More Books

Students also viewed these Databases questions