⊗pyPmLpDE 165 of 208 menu

Entering Data in a Loop in Python

To ask the user the same question multiple times, you need to use the input function in a while loop. And while the specified condition is true, the user will be asked for data.

Let's define a boolean value True to the right of while and place a request for a number in the code block:

while True: tst = input('enter number: ') print(tst)

However, the created loop will repeat the request infinitely. Therefore, we need to set an additional condition to exit it. Let's specify that the loop will work while the entered value is a number. Otherwise, let the loop stop:

while True: tst = input('enter number: ') if tst.isdigit(): print(tst) else: break

Ask the user for their name. If the name is more than 6 characters long, display a message saying it is too long. The loop should stop at this point.

byenru