下面是练习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的更多相关文章

  1. 笨办法学 Python (Learn Python The Hard Way)

    最近在看:笨办法学 Python (Learn Python The Hard Way) Contents: 译者前言 前言:笨办法更简单 习题 0: 准备工作 习题 1: 第一个程序 习题 2: 注 ...

  2. [IT学习]Learn Python the Hard Way (Using Python 3)笨办法学Python3版本

    黑客余弦先生在知道创宇的知道创宇研发技能表v3.1中提到了入门Python的一本好书<Learn Python the Hard Way(英文版链接)>.其中的代码全部是2.7版本. 如果 ...

  3. 笨办法学 Python (第三版)(转载)

    笨办法学 Python (第三版) 原文地址:http://blog.sina.com.cn/s/blog_72b8298001019xg8.html   摘自https://learn-python ...

  4. 笨办法学Python - 习题1: A Good First Program

    在windows上安装完Python环境后,开始按照<笨办法学Python>书上介绍的章节进行练习. 习题 1: 第一个程序 第一天主要是介绍了Python中输出函数print的使用方法, ...

  5. 笨办法学python 13题:pycharm 运行

    笨办法学python 13题 代码: # -*- coding: utf-8 -*- from sys import argv # argv--argument variable 参数变量 scrip ...

  6. 笨办法学python - 专业程序员的养成完整版PDF免费下载_百度云盘

    笨办法学python - 专业程序员的养成完整版PDF免费下载_百度云盘 提取码:xaln  怎样阅读本书 由于本书结构独特,你必须在学习时遵守几条规则 录入所有代码,禁止复制粘贴 一字不差地录入代码 ...

  7. 笨办法学Python 3|百度网盘免费下载|新手基础入门书籍

    点击下方即可百度网盘免费提取 百度网盘免费下载:笨办法学Python 3 提取码:to27 内容简介: 本书是一本Python入门书,适合对计算机了解不多,没有学过编程,但对编程感兴趣的读者学习使用. ...

  8. 《笨办法学 Python(第四版)》高清PDF|百度网盘免费下载|Python编程

    <笨办法学 Python(第四版)>高清PDF|百度网盘免费下载|Python编程 提取码:jcl8 笨办法学 Python是Zed Shaw 编写的一本Python入门书籍.适合对计算机 ...

  9. 笨办法学python 第四版 中文pdf高清版|网盘下载内附提取码

    笨办法学 Python是Zed Shaw 编写的一本Python入门书籍.适合对计算机了解不多,没有学过编程,但对编程感兴趣的朋友学习使用.这本书以习题的方式引导读者一步一步学习编 程,从简单的打印一 ...

  10. 《笨办法学Python 3》python入门书籍推荐|附下载方式

    <笨办法学Python 3>python入门书籍免费下载 内容简介 本书是一本Python入门书,适合对计算机了解不多,没有学过编程,但对编程感兴趣的读者学习使用.这本书以习题的方式引导读 ...

随机推荐

  1. KETTLE——(例)简单的字段转换

    一个简单的小例子:结合数据抽取.简单的字段转换.数据输出. 资源库连接.数据输入.数据输出.参见之前的文章. ​ 基本的转换结构是这样的,我们从表中输入,选择我们需要的字段,已经对应的名称,然后将数据 ...

  2. Java 基础-类与面向对象

    类 Object 类(java.lang.Object)是所有 Java 类的直接或间接父类. 成员方法及变长参数 方法定义: [public | protected | private] [stat ...

  3. springboot An incompatible version [1.1.32] of the APR based Apache Tomcat Native library is installed, while Tomcat requires version [1.2.14]

    1.错误 An incompatible version [1.1.32] of the APR based Apache Tomcat Native library is installed, wh ...

  4. js-用判断音乐或图片是否加载完成的方式来控制页面的现实

    判断页面加载,加完完成后,内容页显示,加载条隐藏 百度搜索方法很多,大多都是: document.onreadystatechange = function() //当页面加载状态改变的时候执行fun ...

  5. SoapUI常用的参数化方法

    本篇文章来讲一下SoapUI在使用中常用的参数化方法字段参数化和使用DataSource调用Excel中的 数据给接口参数化,其中DataSource功能SoapUI开源版没有,大家可以使用破解版, ...

  6. [Usaco2014 Feb] Roadblock

    有一个无向图,共N个节点,编号1至N,共M条边.FJ在节点1,它想到达节点N.FJ总是会选择最短路径到达节点N .作为捣蛋的奶牛Bessie,它想尽量延迟FJ到达节点N的时间,于是Bessie决定从M ...

  7. python+selenium的frame表单切换

    switch_to.frame()                               切换frame switch_to.default_content()                切 ...

  8. HDFS中NameNode发生故障没有备份从SecondNameNode恢复

    1.Secondary NameNode目录结构 Secondary NameNode用来监控HDFS状态的辅助后台程序,每隔一段时间获取HDFS元数据的快照. 在/opt/module/hadoop ...

  9. 【洛谷p1077】摆花

    题外废话: 真的超级喜欢这道题 摆花[题目链接] yy一提醒,我发现这道题和[洛谷p2089] 烤鸡有异曲同工之妙(数据更大了更容易TLE呢qwq) SOLUTION1:(暴搜) 搜索:关于搜索就不用 ...

  10. HTML5随记

    1.浏览器加载HTML的过程是从上至下,因此引用的第三方js文件一定要放到自己定义的js文件的前面,否则引入的js文件将会在加载时失效. 2.html的全局属性包括:accesskey.content ...