下面是当初看这本书时按照书中的代码做的练习,一行一行敲下来的,都已经试运行过,没有错误(基于python3),练习1-练习10
#ex1.py
1 #print("Hello world!")
2 print("Hello again")
3 print("I like typing this.")
4 print("This is fun.")
5 print('Yay!Printing.')
6 print("I'd much rather you 'not'.")
7 print('I "said" do not touch this.')
8 print('')
#ex2.py
1 # A comment, this is so you can read your program later.
# Anything after the # is ignored by python. print("I could have code like this.") # and the comment after is ignored) # You can also use a comment to "disable"or comment out a piece of code:
# print("This won't run.") print("This will run.")
 #ex3.py
1 print("I will now count my chickens:") print("Hens",25+30/6)
print("Poosters",100-25*3%4) print("Now I will count the eggs:") print(3+2+1-5+4%2-1//4+6) print("Is it true that 3+2<5-7?") print(3+2<5-7) print("What is 3+2?",3+2)
print("What is 5-7?",5-7) print("Oh,that's why it's False.") print("How about some more.") print("Is it greater?",5 > -2)
print("Is it greater or equal?",5 >= -2)
print("Is it less or equal?",5 <= -2)
 #ex4.py
1 #给变量cars赋值为100
cars = 100
#给变量space_in_a_car赋值为4.0
space_in_a_car = 4
#给变量drivers赋值为30
drivers = 30
#给变量passengers赋值为90
passengers = 90
cars_not_driven = cars - drivers
cars_driven = drivers
carpool_capacity = cars_driven * space_in_a_car
average_passengers_per_car = passengers // cars_driven print("There are",cars,"cars available.")
print("There are only",drivers,"drivers available.")
print("There will be",cars_not_driven,"empty cars today.")
print("We can transport",carpool_capacity,"people today.")
print("We have",passengers,"to carpool today.")
print("We need to put about",average_passengers_per_car,"in each car.")
 #ex5.py
1 my_name = 'Zed A. Shaw'
my_age = 35 # not a lie
my_height = 74 # inches
my_weight = 180 #lbs
my_eyes = 'Blue'
my_teeth = 'White'
my_hair = 'Brown' print("Let's talk about %s."% my_name)
print("He's %d inches tall."% my_height)
print("He's %d pounds heavy."% my_weight)
print("Actually that's not too heavy.")
print("His teeth are usually %s depending on the coffee."% my_teeth) # this line is tricky,try to get it exactly right
print("If I add %d,%d,and %d I get %d."%(my_age,my_height,my_weight,my_age+my_height+my_weight))
 #ex6.py
1 x = "There are %d types of people."%10
binary = "binary"
do_not = "don't"
y = "Those who know %s and those who %s."%(binary,do_not) print(x)
print(y) print("I said:%r."%x)
print("I also said:'%s'."%y) hilarious = False
joke_evaluation = "Isn't that joke so funny?!%r" print(joke_evaluation % hilarious) w = "This is the left side of..."
e = "a string with a right side." print(w+e)
 #ex7.py
1 print("Mary had a little lamb.")
print("Its fleece was white as %s."%'snow')
print("And everywhere that Mary went.")
print("."*10) # what'd that do? end1 = "C"
end2 = "h"
end3 = "e"
end4 = "e"
end5 = "s"
end6 = "e"
end7 = "B"
end8 = "u"
end9 = "r"
end10 = "g"
end11 = "e"
end12 = "r" # watch that comma at the end. try removing it to see what happens print(end1+end2+end3+end4+end5+end6,end=" ")
print(end7+end8+end9+end10+end11+end12)
 #ex8.py
1 formatter = "%r %r %r %r" print(formatter %(1,2,3,4))
print(formatter %("one","two","three","four"))
print(formatter %(True,False,False,True))
print(formatter %(formatter,formatter,formatter,formatter))
print(formatter %(
"I had this thing.",
"That you could type up right.",
"But it didn't sing.",
"So I said goodnight."
))
 #ex9.py
1 # Here's some new strange stuff,remember type it exactly. days = "Mon Tue Wed Thu Fri Sat Sun"
months = "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug" print("Here are the days: ",days)
print("Here are the months: ",months) print("""
There's something going on here.
With the three double-quotes.
We'll be able to type as much as we like.
Even 4 lines if we want,or 5,or 6.
""")
 #ex10.py
1 tabby_cat = "\tI'm tabbed in."
persian_cat = "I'm split\non a line."
backslash_cat = "I'm \\a\\ cat." fat_cat = '''
I'll do a list:
\t* Cat food
\t* Fishies
\t* Catnip\n\t* Grass
''' print(tabby_cat)
print(persian_cat)
print(backslash_cat)
print(fat_cat)

笨办法学Python(learn python the hard way)--练习程序1-10的更多相关文章

  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. POI向Excel中写入数据及追加数据

    import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFRow; import ...

  2. PHP多图片上传 并检查 加水印 源码

    参数说明:$max_file_size : 上传文件大小限制, 单位BYTE$destination_folder : 上传文件路径$watermark : 是否附加水印(1为加水印,其他为不加水印) ...

  3. ES6标准入门 第二章:块级作用域 以及 let和const命令

    一.块级作用域 1.为什么需要块级作用域? ES5中只有全局作用域和函数作用域,带来很多不合理的场景. (1)内层变量可能会覆盖外层变量: var tem = new Date(); function ...

  4. python 正则表达式 re.search

    #coding:utf-8 import re #将正则表达式编译为pattern对象 #compile(pattern, flags=0) #Compile a regular expression ...

  5. EditPlus配色方案

    找到配置文件:editplus_u.ini配置文件 [Options] Placement=2C00000002000000030000000083FFFF0083FFFFFFFFFFFFFFFFFF ...

  6. Makefile之patsubst

     经常要手写项目的Makefile,或者看其他项目的遗留项目的Makefile,有些makefile内置函数常用, 却用完就忘记了,最近项目中使用patsubst,感觉挺好用的     格式:$(pa ...

  7. VUe.js 父组件向子组件中传值及方法

    父组件向子组件中传值 1.  Vue实例可以看做是大的组件,那么在其内部定义的私有组件与这个实例之间就出现了父子组件的对应关系. 2. 父子组件在默认的情况下,子组件是无妨访问到父组件中的数据的,所以 ...

  8. vue 路由嵌套 及 router-view vue-router --》children

    vue 路由嵌套 vue-router -->children   在项目的很多子页面中,我们往往需要在同一个页面做一个组件的切换,同时保存这个页面的部分数据(比如树形菜单),进而显示不同的数据 ...

  9. Node.JS实战36:写一个WAF中间件!防黑客,防攻击

    如果用Node.JS做Web服务,很多时候是会选择Express的. 本文,将展示如何如何实现一个WAF中间件. WAF有什么用? WAF即Web Application Firewall,Web应用 ...

  10. Vue 基础 day04

    什么是路由 后端路由: 对于普通的网站,所有的超链接都是URL地址,所有的URL地址都对应服务器的资源: 前端路由: 对于单页面应用程序来说,主要是通过URL中的hash(#)来实现不同页面之间的跳转 ...