output of the following code fragment that invokes Twist is:
1 14 3
Explanation:
In the function Twist(),two parameters are passed. First is passed by value and second is passed by reference. If a variable is passed by value then any change made by the function will not affect the original value of that variable but when a variable is passed by reference then any change made by the function will change the original value of that variable. When Twist() function invokes with a=3 and b=2 then value of c=3+2 i.e c=5, a=3*3 i.e. a=9 (value of "a" was 3 earlier) and and b=c+a i.e b=5+9. Here only "b"is passed by reference for variable "s" then any change in it's value will be reflected in the "s". That will update the value of "s" to 14.
The fix to the problem in the code is as follows:
def sum(a, b):
total = a + b
print(total)
sum(1, 0)
<h3>How to determine the problem and the fix to the problem?</h3>
The code is given as:
def sum(a, b):
total = a + b
print(total)
sum(total, a)
sum(1, 0)
When the above code is run, one or both of the following would occur
- An infinite loop because the program cannot end the recursion
- An error when the maximum memory is used
The problem in the code is that, the recursive function do not have a condition to end itself.
The fix to the problem is to remove the recursive definition.
So, we have the fixed code to be
def sum(a, b):
total = a + b
print(total)
sum(1, 0)
Read more about python programs at:
brainly.com/question/26497128
#SPJ1
Answer:
I think it is the last 2 but i am not 100% sure.
Explanation: