Python if Else while

Source: Internet
Author: User

1 getpass module setting password does not display clear text

User name and Password entry program:

Import getpassusername = input ("username:") password = getpass.getpass ("Password:") print (Username,password)

Determine login

_username = "JJ" _password = ' 123456 ' username = input ("username:") password = getpass.getpass ("Password:") if _username = = u Sername and _password==password:    print (' Welcome login.. ') else:    print (' Invalid username or password ')

Guess Age:

AGE_JJ = 35guess_age = Int (input (' Guess Age: ')) if guess_age = = Age_jj:    print (' YES ') elif guess_age > AGE_JJ:    pr Int (' think smaller.. ') else:    print ("Think Bogger..")

Guess 3 times to guess the right to quit, the number of errors reached 3 times also exited

While

The while conditional loop statement is executed if it is submitted as true

AGE_JJ = 35count = 0while count< 3:    guess_age = int (input (' Guess Age: '))    if guess_age = = Age_jj:        print (' YE S ')        break    elif guess_age > AGE_JJ:        print (' think smaller.. ')    else:        print ("Think Bogger..")    Count + = 1

AGE_JJ = 35count = 0while count< 3:    guess_age = int (input (' Guess Age: '))    if guess_age = = Age_jj:        print (' YE S ')        break    elif guess_age > AGE_JJ:        print (' think smaller.. ')    else:        print ("Think Bogger..")    Count + = 1else:    print (' You have tried too many times ... fuck you ... ')

While Else "

If the while condition is true, execute the code in the while

Executes the code inside the else if the condition of the while is false

For

There are two types of python for loops:

1 generates an integer sequence using the range () function.

Print (type range)) for I in range:    print (i)

This sequence can be turned into a list

Print (List (range (10)))

2 for: In the loop list, iterating through the elements of the list in turn

 

names=[' Michael ', ' Bob ', ' Tracy ']for name in Names:    print (name)

  

  

Python if Else while

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.