Post

Python Programming
Python Programming@PythonPr·
Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!
Python Programming tweet media
English
16
13
160
10.4K
Earnest Codes
Earnest Codes@Earnesto037·
@PythonPr Answer: C). 30 Here's why; Step 1: Analyze the function call The function fun(x, y) is called with initial values (x=3) and (y=5). The function is recursive, meaning it calls itself until the base case ((x==0)) is met Step 2: Trace the first recursive
English
1
0
13
482
Othieno Michael Edwards
Othieno Michael Edwards@EdwardsOthieno·
@PythonPr 1. This is a recursive function call; 2. fun(3, 5) calls fun(3 - 1, 3 * 5), which is fun(2, 15). 3. fun(2, 15) calls fun(2 - 1, 2 * 15), which is fun(1, 30). 4. fun(1, 30) calls fun(1 - 1, 1 * 30), which is fun(0, 30). 5. since x == 0, program will return y & y == 30
English
0
0
12
382
Ayo.config ⚙️
Ayo.config ⚙️@Ayo0xx2·
@PythonPr C). fun(x, y) keeps calling itself while reducing x and multiplying y. So fun(3,5) becomes: fun(2,15) to fun(1,30) to fun(0,30). When x hits 0, it returns the final value. Each step stacks a multiplication, not addition. So the end result is 30.
English
0
0
7
442
Python Tech
Python Tech@PythonTech43716·
@PythonPr C) 30 is the right answer. Here we are using recursive function . When function call it's self again and again.
English
0
0
1
109
แชร์