Python notes (one)------while loop (break and Continue)

Source: Internet
Author: User

1.while is more versatile than for: always on if conditions are met

2. Guess the number Game version 1.0

ImportNumPy as NP" "guess the integer 1.0 version: 1. Number of records 2. Give range 3.while statements, including continue, break, Tyr, except" "Answer=np.random.randint (1,101) I=0 whileTrue:Try: Guess=int (Input ('please guess a positive integer of 1-100:')) I+=1ifguess==Answer:Print('It's great! \ n your guess {0} is correct! \ n You used {1} times to guess the answer! I'll give you some praise! '. Format (guess,i)) Break        elifguess<Answer:Print('your answer is too small! Please continue ...')            Print('{0} times guessed value: {1}'. Format (i, guess))Continue        elifGuess>Answer:Print('your answer is too big! Please continue ...')            Print('{0} times guessed value: {1}'. Format (i, guess))Continue    except:        Print('wrong input format! Please check again after typing! ')

Python notes (one)------while loop (break and Continue)

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.