Question

Need in Python! Consider the following program and expected output. Rewrite it using a for loop...

Need in Python!

Consider the following program and expected output. Rewrite it using a for loop and a conditional break statement such that it has the same output.  

HINT: Stay with i as the main loop counter and let j control the break behavior.  

i = 0
while i < 10 and j < 10 :
    j = i * 2 
    print(i, j)
    i += 1

# Output below, for reference - not part of the program!   
0 0
1 2
2 4
3 6
4 8
5 10
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

for i in range(10):
    j = i*2
    print(i, j)
    if j >= 10:
        break

Output:

Add a comment
Know the answer?
Add Answer to:
Need in Python! Consider the following program and expected output. Rewrite it using a for loop...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT