笨办法学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入门书,适合对计算机了解不多,没有学过编程,但对编程感兴趣的读者学习使用.这本书以习题的方式引导读 ...
随机推荐
- PHP 图片+文字+二维码生成小程序分享海报
思路: 1.请求微信接口获取一定尺寸微信二维码 2.准备海报主图,处理尺寸按比例缩放 3.准备分享语录,计算段落高度 4.生成海报:创建画布,分写别入按顺序和位置写入二维码.图片.文字等 5.保存海报 ...
- Oracle-第一篇一些调优技巧
1.查询 1>通过提示,使用索引. 2>使用/*+parallel*/并行查询 3>查看执行计划,调整sql语句或者优化表结构 4>避免使用“*”号 2.表设计:partiti ...
- 贪心(change)
http://codeforces.com/gym/100989/problem/H After the data structures exam, students lined up in the ...
- 洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速$dp\&Floyd$)
洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速\(dp\&Floyd\)) 标签:题解 阅读体验:https://zybuluo.com/Junl ...
- 移动端抓包工具——Fiddler(一)
web端抓包一般利用浏览器自带的检查功能(F12),然后看Network项,根据请求响应判断出问题 移动端怎么抓包呢,这里介绍一款常用的抓包工具——Fiddler 前提: 1.必须确保安装fiddl ...
- 小白学Python(18)——pyecharts 关系图 Graph
Graph-基本示例 import json import os from pyecharts import options as opts from pyecharts.charts import ...
- Ribbon远程调用
Ribbon是客户端的负载均衡机制,它有几种负载均衡机制.默认是轮询,我们也可以自定义规则.通过合理的分配网络请求来减小服务器的压力.项目都是注册到eureka服务器上.通过ribbon去调用其他服务 ...
- Floyd(弗洛伊德)算法(C语言)
转载:https://blog.csdn.net/qq_35644234/article/details/60875818 Floyd算法的介绍 算法的特点 弗洛伊德算法是解决任意两点间的最短路径的一 ...
- more - 在显示器上阅读文件的过滤器
总览 (SYNOPSIS) more [-dlfpcsu ] [-num ] [+/ pattern] [+ linenum] [file ... ] 描述 (DESCRIPTION) More 是 ...
- 关于conda-新手必读
一.管理conda 通过anaconda来安装python及python包,让你不必关心系统是否安装了一些依赖,如zlib等等,anaconda已经集成了这些依赖,可以方便的安装python 下载请点 ...