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
时间: 2025-01-11 08:09:06

python路1---variable的相关文章

python: local variable 'xxx' referenced before assignment

问题发现 xxx = 23 def PrintFileName(strFileName): if xxx == 23: print strFileName xxx = 24 PrintFileName("file") 报错 Traceback (most recent call last): File "C:/Users/Desktop/del.py", line 7, in <module> PrintFileName("file"

python 路 05

一·,三引号不光是多行注释,也是多行打印. 集成开发环境(IDE,Intgrated Development Enviroment) 1.VIM(linux 下的文本编辑器) 2.Emacs (Linux 下文本编辑器) 3.Eclipse(java IDE,支持python,c++,等)4,Visual Studio (微软的IDE) 5.Notepad++,或者 subline python 开发的. pycharm 主要用于python 开发的 二,格式化输出: 占位符  %s strin

python路6__code,fileoperator

1,文件编码 python默认编码,python2默认为ascii,python3默认为utf-8所以说,python3默认支持中文. >>> import sys >>> sys.getdefaultencoding()  #显示python默认编码 'utf-8'2, 2,文件操作通过指针的移动在读取文件,文件打开,指针指向文件开头,文件读完,指针指向文件末尾,指针不会自动回到文件开头,所以说,文件只能读一遍,如果想想再一次从头读取文件,就需要手动将指针指向文件开头

Python 路谱

20160214--->20160824 一口气爬过高山 Happy Valentine's Day 新闻: 201602-1引力波 引力波数据居然是用 Python 分析的 http://www.techug.com/gwpy-ligo-analyze 相关Python包:GWPY 基础--->模块---框架 Web框架: Python和Flask真是太强大了 http://python.jobbole.com/81065/ 1.Django 官网:https://www.djangopro

python路5__购物车小程序练习

1,购物车小程序 需求: (1),启动程序后,打印全部商品列表,用户输入工资 (2),许用户根据商品编号购买商品 (3),用户购买商品,余额不足就退出程序,并打印信息 (4),可随时退出,退出时,打印已购买商品和余额 2,流程图 3,代码 #!/usr/bin/python3 Product_list = [ ('Doido钻戒 ',8000), ('ROLEX手表',20000), ('HuaWei P10',4000), ('AppleWatch',2000), ('Ipad',1000),

python路4&mdash;字典、集合

#!/usr/bin/python3 #字典---增删改查 #穿件一个字典info >>> info = { ... 'student01':'TenLan Wu', ... 'student02':'LongZe Luola', ... 'student03':'XiaoZe Maliya' ... ... } #字典查询 >>> info {'student03': 'XiaoZe Maliya', 'student01': 'TenLan Wu', 'studen

学习python路途中....

有关class类中的属性和方法 def __init__(self, 变量):  这个类定义为某个对象时会自动调用的方法 def __call__(self, 变量):  这个是把类的方法直接当函数来调用了  ,一般是 对象.方法() 调用   ,这个为对象()  调用 def __str__(self, 变量):   这个是对象直接被打印 默认调用的一个方法  一般是 print(对象)  来使用 def __getattr__(self, 变量):   这个是对象调用其属性时,存在即调用,不

python路--字典

字典 不可变类型:整型,字符,元组       键--不可变类型 可变类型:列表,字典 字典两大特点:数据无序,键唯一 创建 dic={'hobby':{'girl_name':'铁锤','age':45}, } 值可为字典 增 dic['name']='alex' dic.update(dic2) 删 dic.pop('age') dic.clear() del dic del dic['name'] 查 print( list(dic.keys())   )   打印出所有的键 , 一个列表

python路-字符

字符                       if  age.isdigit():        #字符串age是数字"12" age = int(age) else: exit() #退出程序 exit("现在我退出了") 截取 print('helloworld'[2:]) 属于  print('el' in 'hello') 格式化   %s   %d     %f msg = '''name =%s,age =%s'''%(name,age) 连接 d2