Question: Python Q4: If Function vs Statement Let's try to write a function that does the same thing as an if statement. def if function(condition, true_result,

Python

Python Q4: If Function vs Statement Let's try to write a function

Q4: If Function vs Statement Let's try to write a function that does the same thing as an if statement. def if function(condition, true_result, false_result) "Return true_result if condition is a true value, and false_result otherwise >>> if function(True, 2, 3) >>> if function(False, 2, 3) >>> if function(3-2, 3-2, 3-2) >>> if function(3>2, 3-2, 3-2) if condition return true_result else return false_result Despite the doctests above, this function actually does not do the same thing as an if statement in all cases. To prove this fact, write functions c, t. and f such that with_if statement prints the number 2, but with_if function prints both and 2 def with_if_statement) >>> result with-if-statement() >> print(result) None if cO return tO else return fO def with_if function) >>> result with-if-function() >> print(result) None return if function(c), tO, fO) def cO) " YOUR CODE HERE def t) " YOUR CODE HERE def fO " YOUR CODE HERE Hint: If you are having a hard time identifying how an if statement and if function differ, consider the rules of evaluation for if statements and call expressions

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!