Consider the following program fragment. Re-write it with Python. j = -3; key = j + 2; for (i = 0; i < 10; i++){ if ((key == 3) || (key == 2)) j--; else if (key == 0) j += 2; else j = 0; if (j > 0) break; else j = 3 - i; } Please add output statements to display the values of j and key in this program.
Added by Christopher S.
Close
Step 1
```python j = -3 key = j + 2 for i in range(10): if key == 3 or key == 2: j -= 1 elif key == 0: j += 2 else: j = 0 if j > 0: break else: j = 3 - i print(f"Iteration {i+1}: j = {j}, key = {key}") Show more…
Show all steps
Your feedback will help us improve your experience
Akash M and 73 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Create a set of two nested for loops. The outer loop will iterate from 5 to 1, decrementing by 1 with each consecutive iteration. Use the letter 'k' for its counter variable name. The inner loop will iterate from 0 to 10 by 2. Use the letter 'i' for its counter variable. Hint: Use the += operator to increment by 2. With each iteration of the inner loop, print both loop index values such as: k = 5, i = 0 k = 5, i = 2 k = 5, i = 4 k = 5, i = 6 k = 5, i = 8 k = 5, i = 10 k = 4, i = 0 k = 4, i = 2 k = 4, i = 4 k = 4, i = 6 k = 4, i = 8 k = 4, i = 10 k = 3, i = 0 k = 3, i = 2 k = 3, i = 4 k = 3, i = 6 k = 3, i = 8 k = 3, i = 10 k = 2, i = 0 k = 2, i = 2 k = 2, i = 4 k = 2, i = 6 k = 2, i = 8 k = 2, i = 10 k = 1, i = 0 k = 1, i = 2 k = 1, i = 4 k = 1, i = 6 k = 1, i = 8 k = 1, i = 10
Akash M.
What will be the value of i after the C statements at the right have been executed i = 3; j = 10; If ((3 * i) < j ) i = i + 2; i = i +3;
Darrick L.
Write Pyihon loop that will siart at 10 and count backwards by 2's (98, 96__) io 54. HOWEVER; aIso want it i0 skip every third priniout 98, 96, 92,90, ,86
Hannah W.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Watch the video solution with this free unlock.
EMAIL
PASSWORD