Python base 5 While loop statement

Source: Internet
Author: User

While Loop statement:

The while statement is used to loop the execution of a program that, under certain conditions, loops through a program to handle the same tasks that require repeated processing.

The format is:

While condition judgment:

The executed statement

Example: Guessing a number game, defining a number, and guessing within three times

Luck_num = 56num2=-1Guess_count=0 whileGuess_count < 3: num2= Int (Input ("Please input your num:"))    ifnum2 >Luck_num:Print("your num is too big")    elifNum2 <Luck_num:Print("your num is too little")    Else:        Print("congratulation your num is correct")         BreakGuess_count+ = 1#the above loop condition does not satisfy the time to execute else. But if the loop above does not exit normally, the else code does not executeElse:    Print("too many times you try")

The while statement has two other important commands, Continue,break, to skip the loop, continue to skip the loop, and break to exit the loop.

Python base 5 While loop statement

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.