Little Turtle Python Video IV lecture (after-school exercise)

Source: Internet
Author: User

1while statement, when the condition is true, it will continue to loop, such as the following example, but can be used ctral + C to force the end

 while ' C ' :    print ("iLove you")

2. Observe the number of prints

Ten  while 0 :    print ("iLove you")    1

3. Note the usage of and (meaning both sides are true)

Ten  + Ten  +

4. Short Circuit logic

Generally speaking, the short circuit logic is worth in a logic, only the first half of the judgment, as long as the first half can determine the result, it will not judge the second half of the logic.

5. Note the condition in the while, that is, 0 is false

num = Int (input (" Enter an integer:"= 0 while num:    = i + 1      = num-1    Print (i)

6.

temp = input ('Please enter an integer:') number=Int (temp) whilenumber:i= Number-1 whileI:Print(' ', end ="') I= I-1J= Number whileJ:Print('*', end ="') J= J-1Print() number= Number-1

7. (Copy the Little Turtle)

ImportRandomtimes= 3Secret= Random.randint (1,10)Print('------------------I love fish C studio------------------')#Here's The Guess assignment first (assigning a value that is definitely not equal to secret)Guess =0#Print () By default, a newline character is automatically added when the string is printed, and the end= "" parameter tells print () to use a space instead of a newline .#Well, the Little turtle feels creative you should try to use end= "JJ"? Print("guess which number the turtle is thinking now:", end=" ") while(Guess! = secret) and(Times >0): Temp=input () Guess=Int (temp) times= Times-1#every time the user enters, the available opportunity is 1    ifGuess = =Secret:Print("I grass, you are a small turtle in the heart of the worm?! ")        Print("Well, there's no reward for guessing! ")    Else:        ifGuess >Secret:Print("elder brother, Big has been big ~ ~ ~")        Else:            Print("Hey, small, small.")        ifTimes >0:Print("Try it again:", end=" ")        Else:            Print("The opportunity t_t")Print("game Over, no play ^_^")

Little Turtle Python Video IV lecture (after-school exercise)

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.