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