笨办法学Python(learn python the hard way)--练习程序39-40
下面是练习39-练习40,基于python3
#ex39.py
1 ten_things = "Apples Oranges Crows Telephone Light Sugar" print("Wait there's not 10 things in that list,let's fix that.") stuff = ten_things.split(' ') more_stuff = ["Day", "Night", "Song", "Frisbee", "Corn", "Banana", "Girl", "Boy"] while len(stuff) != 10:
next_one = more_stuff.pop()
print("Adding: ", next_one)
stuff.append(next_one)
print("There's %d items now." % len(stuff)) print("There we go: ", stuff) print("Let's do some things with stuff.") print(stuff[1])
print(stuff[-1]) # whoa! fancy
print(stuff.pop())
print(' '.join(stuff)) # what? cool!
print('#'.join(stuff[3:5])) # super stellar!
#ex40.py
1 # list things = ['a', 'b', 'c', 'd']
print(things[1]) things[1] = 'z'
print(things[1]) print(things) # dict stuff = {'name': 'Zed', 'age': 36, 'height': 6*12+2}
print(stuff['name'])
print(stuff['age'])
print(stuff['height']) stuff['city'] = "San Francisco"
print(stuff['city']) stuff[1] = "Wow"
stuff[2] = "Neato"
print(stuff[1])
print(stuff[2])
print(stuff) del stuff['city']
del stuff[1]
del stuff[2]
print(stuff)
#ex40+.py
1 # 练习 cities = {'CA': 'San Francisco', 'MI': 'Detroit', 'FL': 'Jacksonville'} cities['NY'] = 'New York'
cities['OR'] = 'Portland' print(cities)
print(cities.values())
print(cities.keys())
print(cities.items()) def find_city(themap, state):
if state in themap:
return themap[state]
else:
return "Not found." # ok pay attention!
cities['_find'] = find_city j = cities.keys()
for i in j:
city_found = cities[i]
print(city_found) while True:
print("State?(ENTER to quit)",end = '')
state = input("> ") if not state: break # this line is the most important ever! study!
city_found = cities['_find'](cities,state)
print(city_found)
笨办法学Python(learn python the hard way)--练习程序39-40的更多相关文章
- 笨办法学 Python (Learn Python The Hard Way)
最近在看:笨办法学 Python (Learn Python The Hard Way) Contents: 译者前言 前言:笨办法更简单 习题 0: 准备工作 习题 1: 第一个程序 习题 2: 注 ...
- [IT学习]Learn Python the Hard Way (Using Python 3)笨办法学Python3版本
黑客余弦先生在知道创宇的知道创宇研发技能表v3.1中提到了入门Python的一本好书<Learn Python the Hard Way(英文版链接)>.其中的代码全部是2.7版本. 如果 ...
- 笨办法学 Python (第三版)(转载)
笨办法学 Python (第三版) 原文地址:http://blog.sina.com.cn/s/blog_72b8298001019xg8.html 摘自https://learn-python ...
- 笨办法学Python - 习题1: A Good First Program
在windows上安装完Python环境后,开始按照<笨办法学Python>书上介绍的章节进行练习. 习题 1: 第一个程序 第一天主要是介绍了Python中输出函数print的使用方法, ...
- 笨办法学python 13题:pycharm 运行
笨办法学python 13题 代码: # -*- coding: utf-8 -*- from sys import argv # argv--argument variable 参数变量 scrip ...
- 笨办法学python - 专业程序员的养成完整版PDF免费下载_百度云盘
笨办法学python - 专业程序员的养成完整版PDF免费下载_百度云盘 提取码:xaln 怎样阅读本书 由于本书结构独特,你必须在学习时遵守几条规则 录入所有代码,禁止复制粘贴 一字不差地录入代码 ...
- 笨办法学Python 3|百度网盘免费下载|新手基础入门书籍
点击下方即可百度网盘免费提取 百度网盘免费下载:笨办法学Python 3 提取码:to27 内容简介: 本书是一本Python入门书,适合对计算机了解不多,没有学过编程,但对编程感兴趣的读者学习使用. ...
- 《笨办法学 Python(第四版)》高清PDF|百度网盘免费下载|Python编程
<笨办法学 Python(第四版)>高清PDF|百度网盘免费下载|Python编程 提取码:jcl8 笨办法学 Python是Zed Shaw 编写的一本Python入门书籍.适合对计算机 ...
- 笨办法学python 第四版 中文pdf高清版|网盘下载内附提取码
笨办法学 Python是Zed Shaw 编写的一本Python入门书籍.适合对计算机了解不多,没有学过编程,但对编程感兴趣的朋友学习使用.这本书以习题的方式引导读者一步一步学习编 程,从简单的打印一 ...
- 《笨办法学Python 3》python入门书籍推荐|附下载方式
<笨办法学Python 3>python入门书籍免费下载 内容简介 本书是一本Python入门书,适合对计算机了解不多,没有学过编程,但对编程感兴趣的读者学习使用.这本书以习题的方式引导读 ...
随机推荐
- JsonDatetime
ToDatetime public DateTime JsonDateTimeConvert(string time) { //try //{ if (String.IsNullOrEmpty(tim ...
- Linux(Ubuntu)常用命令(三)
查看时间 cal :显示当前日期. cal :显示全年日历./ cal -y 显示当年日历. date :显示当前时间. 这几个一般不会用到了解即可. 查看进程信息 ps :显示当前进程. - ...
- Ubuntu操作系统的总结操作
一.Ubuntu系统环境变量 Ubuntu Linux系统环境变量配置文件分为两种:系统级文件和用户级文件 1.系统级文件: /etc/profile:在登录时,操作系统定制用户环境时使用的第一个文件 ...
- 【mysql连接与mysqldump】INFORMATION_SESSION_VARIABLES feature is disabled
摘要: mysql5.7 客户端连接出现:INFORMATION_SESSION_VARIABLES feature is disabled问题: mysqldump: Couldn't execut ...
- Java-集合第一篇认识Java集合
1.4种集合类型 List:有序可重复集合. Queue:队列集合. Set:无序不可重复集合. ------------------------------- Map:关系映射集合. 2.所有的集合 ...
- [集合Set]HashSet、LinkedHashSet TreeSet
Set Set是不包含重复元素的集合.更正式地,集合不包含一对元素e1和e2,使得e1.equals(e2),并且最多一个空元素. 无索引,不可以重复,无序(存取不一致) Set接口除了继承自Coll ...
- xps9560黑苹果展示
花费了一些时间来安装黑苹果 - - ., 展示一波 更换了DW1820a无线网卡,花费70+ 手上这台笔记本,在安装黑苹果的时候基本没遇见太大的问题,一路顺风顺水. 桌面,程序坞调小放在左侧 极 ...
- Linux压缩、解压
gzip压缩: 归档,压缩,yourFloder文件夹生成yourName.tar.gz: - tar -zcvf yourName.tar.gz yourFloder 解压yourName.tar. ...
- ASE Code Search
重现基线模型 Hamel's model 基线模型原理 如何实现semantic search?在已有数据库的基础上,衡量一个句子和每段代码的相关性再进行排序,选出最优代码片段即可实现一个通用的cod ...
- winsows CMD及Linux命令大全 欢迎补充
CMD命令:开始->运行->键入cmd或command(在命令行里可以看到系统版本.文件系统版本) CMD命令锦集 1. gpedit.msc-----组策略 2. sndrec32--- ...