Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - There are several times in python about the while loop, such as ending the program after five errors, and how many times are left in each error prompt.
There are several times in python about the while loop, such as ending the program after five errors, and how many times are left in each error prompt.
Import? at will

Sui Jishu? =? random.randint( 1, 10)

Count? =? 10

# If the count is less than or equal to 10, the execution of the sub-code block is started.

What time? Count? & lt=? 10? :

# Step by step, directly convert the string input by the user into an integer.

Guess what? =? int(input(' guess & gt; & gt:'))

What if? Guess what? ==? Random thoughts:

Print ('Congratulations, that's right!' )

break

Elif? Guess what? & gt? Random thoughts:

Count? =? Count? -? 1

Print ('too big! What's left %s? Second chance? % count)

What if? Count? ==? 0:

break

Elif? Guess what? & lt? Random thoughts:

Count? =? Count? -? 1

Print ('is too small. What's left? %s? Second chance? % count)

What if? Count? ==? 0:

Break, your while loop condition judgment is repeated. There is another layer of judgment below.

Input should be placed in a loop, otherwise you will only be asked to input once when executing the code.

When you know more about this program, you can add something, such as judging whether the user inputs numbers. What if you enter a string?

It is recommended to use Pycharm to write code, which is recognized as the most convenient python editor. Automatic indentation, can be debugged. It is very convenient and can be debugged immediately.

You can go to a treasure and spend 5 yuan to buy an activation code.

Give you a screenshot to experience.