一 : 密文密码_getpass
import getpass #密文密码 需要导入的标准库_username = 'chenqiang'_password = '123456'username = input("username :")# password = getpass.getpass("password :") //使用 getpass 方法密文password = input("password :")if _username == username and _password == password: print('welcome user {name} login...'.format(name=username))else: print('Invalid username or password')print('ddd')
二 : 输出格式
name = input("name : ")age = int(input("age : ")) # integer raw_input = input# print(type(age), type(str(age))) //type()打印变量类型job = input("job : ")salary = input("salary : ")print() 方法一:info = '''--------- info of %s ----------Name:%sAge:%dJob:%sSalary:%s''' % (name, name, age, job, salary) 方法二:info2 = '''--------- info of {_name} ----------Name:{_name}Age:{_age}Job:{_job}Salary:{_salary}'''.format(_name=name, _age=age, _job=job, _salary=salary) 方法三:info3 = '''--------- info of {0} ----------Name:{0}Age:{1}Job:{2}Salary:{3}'''.format(name, age, job, salary)print(info3)
三: while for 循环
while True: print('count :',count) count += 1 if count == 1000: break
for i in range(0,10): if i < 3: print('loop :',i) else: continue #跳出本次循环 进入下一个循环 print('呵呵')
四:猜数游戏
方法1: age_of_oldboy = 56count = 0while count < 3: guess_age = int(input('guess age:')) if guess_age == age_of_oldboy: print('yes,you got it') break //如果猜对了-结束 elif guess_age > age_of_oldboy: print('think smaller!') else: print('think bigger!') count += 1 if count == 3: //三次后询问是否继续 countinue_confirm = input('do you want to keep guessing..??') if countinue_confirm != 'n': count = 0else: print('you have tried too many times..fuck off')
方法2: age_of_oldman = 56for i in range(3): guess_age = int(input('guess age:')) if guess_age == age_of_oldman: print('yes,you got it') break #破坏循环 else 也不走了 elif guess_age > age_of_oldman: print('think smaller!') else: print('think bigger!')else: print('you have tried too many times..fuck off')