0

I have to make a program that when I enter a box_size number it show the box. They user should then be able to put in another number and repeat the process. Only when they type 0 should the program stop.

I've tried adding While True, if, and else statements and breaks but none of them stop the program from running.

#Input
box_size=input("box_size:" )
box_size=int(box_size)
for row in range(box_size):
  for col in range(box_size*2):
    print('*', end='')
  print()
print()

#Output
box_size:6
************
************
************
************
************
************

2 Answers 2

2

Put while True: around the code. Then if the user enters 0, break out of the loop.

while True:
    box_size=input("box_size:" )
    box_size=int(box_size)
    if box_size == 0:
        break
    for row in range(box_size):
      for col in range(box_size*2):
        print('*', end='')
      print()
    print()
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I've been struggling with this for hours.
0

Try this simpler one. The box_size is initiated 1, then use it in the while loop. As long as the box_size is more than 0, the loop will always be executed.

box_size = 1
while box_size > 0:
    box_size = int(input("box_size:" ))
    for row in range(box_size):
        for col in range(box_size*2):
            print('*', end='')
        print()
    print()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.