Python Basics 1

Source: Internet
Author: User

Tag: name does not succeed COM BSP input time and get class

1. Input and output.

User input:

Name = Input ("username:") #在py2里用raw_input输入, with inputpasswd = input ("Password:") age = Int (input ("Age:"))

Output 1

Print (type age) #输出变量类型, default is Strprint (NAME,PASSWD)

Output 2

INFO1 = "------------info of---------------username:%spassword:%sage:%d"% (name,passwd,age) print (INFO1)

Output 2

Info2 = "-----------info of {_name}-----------------username:{_name}password:{_password}age:{_age}". Format (_ Name=name, _PASSWORD=PASSWD, _age=age,) print (Info2)

2.getpass encryption

Import getpassusername = "Fengxiaoli" password = "123456" name = Input ("username:") passwd = Getpass.getpass ("Password:") # Note Getpass module does not succeed in Pycharm, you can perform tests on the command line if name = = Username and passwd = = Password:print ("Welcome {_username} login". Format ( _username=name)) else:print ("Invalid login")

3.while,for Cycle

 #猜数字1age  = 50count=0while count < 3:     _age = int (Input ("Age:"))     if _age == age  :        print ("You guessed right")          break    elif _age > age:          print ("The number is too big")      else:         print  ("The number is too  small ")     count +=1else :    print (" You tried  too many times ") 
 guess Digital 2age = 50for i in range (3):     _age = int (Input ("Age:"))     if _age == age :         print ("You guessed right")          break    elif _age > age:          print ("The number is too big")      else:         print  ("the number is too  Small ") Else :    print (" You tried too many times ") 
Guess the number 3age = 50count=0while count < 3:    _age = int ( Input ("Age:"))     if _age == age :         print ("You guessed right")         break     elif _age > age:          Print ("The number is too big")     else:          print  ("The number is too small")      count +=1    if count == 3:         continue_confirm=input ("Do you want continue ...")         if continue_confirm !=  "n":             count  = 0 


Python Basics 1

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.