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 ...
随机推荐
- a various of context
ContextWrapper.getApplicationContext():Return the context of the single, global Application object o ...
- How Android Draws Views
https://developer.android.com/guide/topics/ui/how-android-draws.html
- 几种判断asp.net中session过期方法的比较
方法一:最麻烦也是最容易想到的方法,在每个页面的page_load()方法里面判断: protected void Page_Load(object sender, EventArgs e) { if ...
- js控制打印 转的
很多时候,我们在做系统的时候要做打印功能,打印在js中其实很简单,不过这个很简单的代码并不能满足我们的特定需求,比如我们需要打印的表单在很多文字的中间,或者文字中包含一些广告或者图片什么的,这就很难用 ...
- Camel routes in Spring config file
The normal spring bean definition configuration file, the xsi:schemaLocation only has two: beans and ...
- VBS_For Each...Next
For Each...Next 循环与 For...Next 循环类似.For Each...Next 不是将语句运行指定的次数,而是对于数组中的每个元素或对象集合中的每一项重复一组语句.这在不知道集 ...
- MVC学习IIS的不同版本(一)
一:IIS5.0运行在进程InetInfo.exe中,该进程寄宿着一个名为World Wide Publishing Service(W3VC)的window服务. W3VC的主要功能:包括HTTP请 ...
- Android || IOS录制mp3语音文件方法
Android Android Supported Media Formats : http://developer.android.com/guide/appendix/media-formats. ...
- Best Cow Fences_二分&&DP
Description Farmer John's farm consists of a long row of N (1 <= N <= 100,000)fields. Each fie ...
- WCF客户端和服务端配置
服务端: <system.serviceModel> <services> <service name="Microsoft.ServiceModel.Samp ...