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 ...
随机推荐
- [Python陷阱]os.system调用shell脚本获取返回值
当前有shell个脚本/tmp/test.sh,内容如下: #!/bin/bashexit 11 使用Python的os.system调用,获取返回值是: >>> ret=os.sy ...
- hdu 2037
PS: - -原本想的是排序开始时间和消耗时间..后来想到可以排序结束时间..后来还wa了一次,因为排序的时候溢出了 思路: 1 3 //13 4 //20 7 3 8 2 9 5 10 //36 ...
- linux基础命令(二)用户管理和权限管理
- 【LeetCode OJ】Max Points on a Line
Problem: Given n points on a 2D plane, find the maximum number of points that lie on the same straig ...
- CodeForces 416D (贪心)
Problem Population Size 题目大意 给一个长度为n的序列,由 -1 和正整数组成,-1表示任意的正整数. 将序列分成若干段,使得任意段都是等差数列,求最少段数. 解题分析 可以发 ...
- HDU 3357
http://acm.hdu.edu.cn/showproblem.php?pid=3357 给出公司间的控股关系,问有多少组不合法数据,自己控股自己不合法,a控股b,b控股c,则a控股c 其实就是找 ...
- HDU 5000
http://acm.hdu.edu.cn/showproblem.php?pid=5000 题意:有n种属性,每种属性的数值可以是0-T[i],当一个人属性全部小于等于另一个人的属性时,小的那个人会 ...
- ZOJ 3811
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5343 网络赛这水题没写过太伤了,赛后写了下1A. 当时钻牛角尖一定要用k次bf ...
- document操作
1.windows对象操作 事件两个参数sender:代表事件源,即谁触发的事件e:代表事件数据load(sender,e)事件是一个特殊的委托(代理)2.document对象操作找元素:1.根据id ...
- Makefile学习(1) arm-linux-ld arm-linux-objcopy arm-linux-objdump
记录自己所学的点点滴滴O(∩_∩)O哈哈~ makefile: link.bin: start.o main.o arm-linux-ld -Tlink.lds -o link.elf $^ arm- ...