Post

Python Coding
Python Coding@clcoding·
What is the output of following Python Code?
Python Coding tweet media
English
144
50
393
85.8K
Coding Computing Coach
Coding Computing Coach@CodingComputing·
@clcoding Answer: 20 15 (on separate lines) Solution: Quick recap, a `while` loop's body is repeatedly executed until the condition is condition remains truthy. Here num = 20 assigns the value 20 to `num`. while num > 10: ... This loop will execute as long as num>10 +
English
1
1
8
1.2K
Coding Computing Coach
Coding Computing Coach@CodingComputing·
@clcoding Notice that the inequality is `>`, not `>=`. So the condition is satisfied only when num is strictly greater than 10. Currently num is 20, so the condition is satisfied. Thus the loop executes print(num) prints 20 to the output. num -= 5 deducts 5 from num. So +
English
1
0
0
52
Coding Computing Coach
Coding Computing Coach@CodingComputing·
@clcoding num, which was 20, now becomes 15. That is the end of the loop body. Hence the loop condition is checked, to determine if the loop is to be run again. The condition is num>10. num is 15 so the condition holds True. Hence the loop executes again +
English
1
0
0
46
Coding Computing Coach
Coding Computing Coach@CodingComputing·
@clcoding print(num) prints the value of num, which is now 15, to the output. The net output so far is 20 15 Now, num-=5 reduces the value of num by 5. So, num, which was 15, now reduces to 10. This is the end of the loop body. +
English
1
0
0
30
Chia sẻ