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 ...
随机推荐
- Java中线程的锁和数据库中的事务隔离级别
当涉及到两个或多个线程操作同一个资源时,就会出现锁的问题. 数据库中的某一条记录或者是某一个对象中的字段,可以修改,也可以读取,一般情况下,读取的那个方法应该加锁(即用synchronized互斥), ...
- Office word excel电子表格在线编辑的实现方法
Office xp之后的版本支持通过webdav协议(http的扩展)直接编辑服务器上的文件. IIS(6.0)支持webdav,这在IIS管理器的web服务扩展中可以看到.利用IIS作为webdav ...
- Ch2.Making Reconmmendation in PCI
做<Programing Collective Intelligence>中chapter 2.Making Recommendation的实例,有3个问题花了好长时间: 1. 遇到报错& ...
- 自定义UIAlertView
You can change accessoryView to any own customContentView in a standard alert view in iOS7 [alertVie ...
- javaweb-dbcp2
package cn.itcast.utils; import java.io.InputStream;import java.sql.Connection;import java.sql.Drive ...
- du -sh 目录名称 查看目录大小
du -sh 目录名称 查看目录大小 df -h 查看磁盘使用情况
- 爬虫再探实战(四)———爬取动态加载页面——请求json
还是上次的那个网站,就是它.现在尝试用另一种办法——直接请求json文件,来获取要抓取的信息. 第一步,检查元素,看图如下: 过滤出JS文件,并找出包含要抓取信息的js文件,之后就是构造request ...
- Channel Allocation_四色定理
Description When a radio station is broadcasting over a very large area, repeaters are used to retra ...
- postgresql 分区表创建及测试
1 建立分区 1.1. 创建主表 CREATE TABLE measurement ( city_id int not null, logdate date ...
- TC Hash Filter
Overview The u32 filter allows you to match on any bit field within a packet, so it is in some ways ...