Day1_python base _15.while Loop

Source: Internet
Author: User

There is a cycle called the cycle of death, once triggered, will run an everlasting, lasting.

Lasting code

Count = 0while  True:    print(" You are the wind I am the sand, tangled up to the horizon ... " , Count)     +=1

In fact, in addition to the time, nothing is eternal, dead loop or less write as good

The code above loops out 100 times.

Count = 0while  True:    print(" You are the wind I am the sand, tangled up to the horizon ... " , Count)     +=1    If count = =:        print(" go to your mother's wind and sand, you these pants are people, Wearing pants is a ghost of the Smelly Man . " )        break

Back to the example above for the loop, how to enable the user to constantly guess age, but only to give up to 3 times, and then guess the wrong to quit the program

#!/usr/bin/env python#-*-coding:utf-8-*-My_age= 28Count=0 whileCount < 3: User_input= Int (Input ("input your guess num:"))     ifUser_input = =My_age:Print("Congratulations, you got it!")         Break    elifUser_input <My_age:Print("Oops,think bigger!")    Else:        Print("Think smaller!") Count+ = 1#Each loop counter +1Else:    Print("guess it's wrong so many times, you idiot.")

Day1_python base _15.while Loop

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.