Python字典笔记
db={}
def newuser():
prompt='login desired:'
while True:
username=input(prompt)
if username in db:
prompt='name taken,try another:'
continue
else:
break
password=input('please enter password:')
db[username]=password
def olduser():
username=input('please enter username:')
password=input('please enter password:')
psw=db.get(username)
if password==psw:
print ('Welcome back %s' % username)
else:
print ('login incorrect!')
def showmenu():
prompt='''
(N)ew User Login
(O)ld User Login
(Q)uit
Please enter your choice
'''
done=False
while not done:
chosen=False
while not chosen:
try:
choice=input(prompt).strip()[0].lower()
except (EOFError,KeyboardInterrupt):
choice='q'
print ('\nYou picked:[%s]' %choice)
if choice not in 'noq':
print ('Invaild option, try again ')
else:
chosen='True'
if choice=='q':
done=True
if choice=='n':
newuser()
if choice=='o':
olduser()
if __name__=='__main__':
showmenu()
Python字典笔记的更多相关文章
- Python字典--笔记
<Python3程序开发指南> 映射:键-值数据项的组合 Python3支持两种无序的映射类型:内置的dict类型.标准库中的collections.defaultdict类型. Pyth ...
- python学习笔记整理——字典
python学习笔记整理 数据结构--字典 无序的 {键:值} 对集合 用于查询的方法 len(d) Return the number of items in the dictionary d. 返 ...
- python学习笔记(一)元组,序列,字典
python学习笔记(一)元组,序列,字典
- 【python学习笔记】4.字典:当索引不好用时
[python学习笔记]4.字典:当索引不好用时 字典是python中唯一内建的map类型 创建: key可以为任何不可改变的类型,包括内置类型,或者元组,字符串 通过大括号: phonebook={ ...
- Python学习笔记3-Python元组、数组、字典集合的操作
在Python中数组中的每一项可以是不同的数据类型 元组:只能读不能写的数组 aTuple=(1,'abc','tmc',79.0,False) print aTuple[1:3] print typ ...
- Python学习笔记(七)—字典的学习
总结内容: 1.字典的定义 2.字典的好处 3.字典的增删改查 4.字典常用方法及内置函数 5.字典的多层嵌套 6.字典的循环 7.字典小练习 1.字典的定义 字典是另一种可变容器模型,且可存储任意类 ...
- python学习笔记:第五天( 字典)
Python3 字典 字典是另一种可变容器模型,且可存储任意类型对象. 字典的每个键值(key=>value)对用冒号(:)分割,每个对之间用逗号(,)分割,整个字典包括在花括号({})中 ,格 ...
- Python学习笔记(字典)
今天学习一个python中的基本类型--字典(dictionary) 字典这种数据结构有点像我们平常用的通讯录,有一个名字和这个名字对应的信息.在字典中,名字叫做“键”,对应的内容信息叫做“值”.字典 ...
- [Python爬虫笔记][随意找个博客入门(一)]
[Python爬虫笔记][随意找个博客入门(一)] 标签(空格分隔): Python 爬虫 2016年暑假 来源博客:挣脱不足与蒙昧 1.简单的爬取特定url的html代码 import urllib ...
随机推荐
- UVA 1639(组合数学)
根据组合数公式C(m,n),由于m可能达到20万,因此转换为ln,之后可以表达为ln(m!)-ln(n!)-ln((m-n)!); 求每一个c[n]时,也要根据杨辉三角求组合数进行转化. 注意long ...
- iOS 微信 音频 视频自动播放
iOS 微信 音频 视频自动播放 http://www.w3ctech.com/topic/1165
- magento获取页面url的办法还有magento的常用函数
<?php echo $this->getStoreUrl('checkout/cart');?> 获取结账页面的url:<?php echo $this->getUrl ...
- Linux--/tmp目录文件重启后自动删除
源博客 http://blog.itpub.net/24996904/viewspace-769327/ 在/etc/default/目录下有个rcS文件,文件内容如下:## /etc/default ...
- CSS 实现:元素相对于文档水平垂直居中
[要求]:如何用 CSS 实现水平/垂直居中一个元素(相对于文档) <body> <div class="content"></div> < ...
- bold, big, blink
- php函数 date() 详细资料
date_default_timezone_set(PRC); /*把时间调到北京时间,php5默认为格林威治标准时间*/ date () a: "am"或是"pm&qu ...
- C#裁剪照片并保存
/// <summary> /// /// </summary> /// <summary> /// 生成缩略图 /// </ ...
- HDU 2089 数位dp/字符串处理 两种方法
不要62 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- ZOJ 1088 System Overload
原题链接 题目大意:浙大的破网络容量有限,太多人同时使用BBS就会系统崩溃.为了保持系统正常工作,过载时就需要切断部分用户.规则是把玉泉所有的建筑从1到n编号,设定一个常数m.从1开始数,第m幢建筑的 ...