首页 > 代码库 > python路1---variable

python路1---variable

#!/usr/bin/python3        #使用哪个python解释器运行该脚本

#python3默认编码为unicode,支持中文
name = 侯亮平
print (name)

#用户输入函数input()
import getpass
Username = input(Username:)
Passwd = input(Passwd:)
Passwd_get = getpass.getpass(Passwd:)        #密码隐式输入

print (type(Username),type(Passwd),type(Passwd_get))

#举例:录入一个产品信息,然后打印
ProductName = 六神花露水
ProductBrand = 六神
ProductPlace = 中国上海
Productfunc = 驱蚊止痒
Productprice = 9.8
print (
    ‘‘‘
    --------------产品信息--------------
    产品名:%s
    品牌  :%s
    产地  : %s
    功效  : %s
    价格      : %f    

    ‘‘‘    % (ProductName,ProductBrand,ProductPlace,Productfunc,Productprice)

    )

#流程语句 :if...else
#举例:模拟cisco路由器的登录认证,三次尝试失败需等待10s,
import getpass
import time
import os
Count = 0
while True:
    UserName = input(Username:)
    PassWd = getpass.getpass(Passwd:)
    if  UserName ==cisco and PassWd == cisco:
        print (Congrituations :authentication successed!!)
        break
    else:
        print (Authencation failed:username not exist or passwd not right )
        Count +=1
        if Count == 3 :
            print (Try too many times,Please wait ten seconds)
            time.sleep(10)
            os.system(clear)
            Count = 0

python路1---variable