What is the value of price, meal1? a. 8 b. 10.0 c. 12.0 d 14 e. None of the above What is the value of price_ meal2? a. 5.0 b. 6.0 c. 8.5 d. 9.5 e. None of the above. What is the value of price_meal3? a. 8.5 b. 9.5 c. 10.0 d. 11 e. None of the above. For question 26, refer to the following code: 1. def mystery2(a, b): 2. if b = = 1: 3. return 0 4. return a + mystery2(a, b-l) What is the value of mystery2(4, 6)? a. 0 b. 4 c. 20 d. 24 e. None of the above. For question 27, refer to the following code: def mystery3(a): if len(a) = = 1: if a[0]. isdigit(): return int(a[0]) else: return 0 else return mystery3(a[0])+ mystery3(a[1]) What is the value of mystery3(‘CISC is fun’)? a. 0 b. 12 c. ‘Hello, world!’ d. This would cause an error
Expert Answer
26th and 27th questions are in python in which I guess you need help.
26- In the 26th question, recursion is being used with the base condition as b==1
Initially the call is mystery2(4,6) ,where the value of a is 4 and b is 6. Since b is 6, the base condition is false and the method is called recursively. In each call b is decremented by 1, so in total 5 calls are made resulting in the return value of 20
The complete calculation is shown in the below image
ANSWER: 20
27- When mystery3(‘CISC is fun!’) is called, it would go to line 8 as len(a) is not equal to 1. In line 8, the method is again called recursively as mystery3(‘C’)+mystery3(‘ISC is fun!’).
mystery3(‘C’) would return 0(line 6) as its length is equal to 1 and C.isdigit() is false.
mystery3(‘ISC is fun!’) would go to line 8 resulting in mystery3(‘I’)+mystery3(‘SC is fun!’).
So in each call mystery3(a[0]) part would generate 0 and add it to the final return value.
The return value and the recursive calls generated are shown in the image below
ANSWER: 0