The function and process control of Python learning

Source: Internet
Author: User
This article is mainly for you to introduce the Python learning function and process control, with a certain reference value, interested in small partners can refer to

#猜年龄大小, users guess up to three times

Age = i = 0 when I < 3:     guess_age = int (input ("Please input your answer:"))     if Guess_age > Age:         prin T ("Too Big...try Again")     Elif Guess_age < age:         print ("Too small...try Again")     else:         Print ("you guessed it!")         Break     i + = 1     if i = = 3:

#猜年龄, ask if you want to play every three times

Age = $ for I in range (1,100):     guess_age = int (input ("Your answer:"))     if Guess_age > Age:         pri NT ("Too Big...try Again")     Elif Guess_age < age:         print ("Too small...try Again")     else:         Print ("You guessed it!")     If i%3 = = 0:         choice = input ("Would like play again?") Yes or no ")         if choice = =" Yes ":             continue         if choice = =" No ": Break     Else:         continue

#登录验证, input error three times lock user

f = open (' C:/user_passwd.txt ', ' r ') j = 3 System_user_name = str (f.readline ()) system_passwd = str (f.readline ()) F.close () For I in range (1,5):     user_name = str (input ("Your UserID:"))     password = str (input ("passwd:"))     if i = = 3:         s = open (' C:/user_passwd.txt ', ' r+ ')         s.write ("\nlocked")         s.close ()         print ("This user is locked!")         break     Else:         if user_name + ' \ n ' = = system_user_name and Password = = system_passwd:             print ("Welcome" + US Er_name + ' \ n ' + "has a good time!")             Break         Else:             J-= 1             i + = 1
            Print ("UserID or password is wrong,please try once again and you have" + \              Str (j) + ' Times choice ')

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.