下面是当初看这本书时按照书中的代码做的练习,一行一行敲下来的,都已经试运行过,没有错误(基于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. laravel 设置自定义 Validator

    转自:https://learnku.com/docs/laravel/5.4/validation/1234#custom-validation-rules 自定义验证规则 Laravel 提供了许 ...

  2. 使用fiddler,提示系统找不到相应的文件FSE2.exe文件

    使用fiddler时候遇到了如下问题: Rules中customize rules 时,提示系统找不到相应的文件FSE2.exe文件. 这个文件的位置可以在Tools->opinions-> ...

  3. 【MM系列】SAP MM模块-基础配置第一篇

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP MM模块-基础配置第一篇   ...

  4. unity全屏截图

    using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; ...

  5. Linux命令整理 - 通用版

    通用版 - 系统架构 /dev 设备文件夹 null 有去无回 mouse /sbin 系统管理必备程序 cfdisk.dhcpcd.dump.e2fsck.fdisk.halt.ifconfig.i ...

  6. 宝塔 windows下apache环境下禁止某文件夹内运行PHP脚本、禁止访问文件

    首先我们来看两段对上传目录设置无权限的列子,配置如下: //在宝塔下如用/upload这个路径应用无效,一定要C:/wwwroot/upload才有效果 <Directory "要去掉 ...

  7. 最新版 Mysql 8.0.16 创建用户权限更新回收权限

    1.创建用户语法 : create user ‘写你自己的用户名’@‘写你需要哪个IP连接你的用户(%表示所有)’ identified by ‘密码’; 案例: create user ‘wangx ...

  8. C++解析XML字符串

    项目交互遇到了需要VC++中解析XML字符串,故花了点时间了解了下VC++中解析XML的诸多方法主要包括三种:msxml(微软提供).markup.TinyXml. 开始花了点时间使用msxml3,虽 ...

  9. npm模块管理器

    npm模块管理器 地址: http://javascript.ruanyifeng.com/nodejs/npm.html#

  10. python 更快地判断数字的奇数还是偶数

    使用 按位与运算符(&) 将能更加快速地判断一个整数是奇数还是偶数 使用举例如下: def check_number(n): if n & 1: return '奇数' else: r ...