下面是当初看这本书时按照书中的代码做的练习,一行一行敲下来的,都已经试运行过,没有错误(基于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. 搭建 Git 服务器(基于 CentOS 7)

    服务器上的-Git-架设服务器-官网参考 对于规模比较小的团队,可以直接搭建 Git 服务器,逐个收集研发同学的证书配置进来即可.如果团队规模比较大,可以直接采用 GitLab.Drone 等现成的带 ...

  2. 视频格式转换.ZC资料

    1.20191013: ZC:这些都是 2015年做的尝试,之前貌似没有记录下来,现在 再次用到,把用到的记录下来: ZC: (1) 使用的视频格式转换工具是 "??/XiGua Yings ...

  3. 20190925 On Java8 第二十二章 枚举

    第二十二章 枚举 基本 enum 特性 创建 enum 时,编译器会为你生成一个相关的类,这个类继承自 Java.lang.Enum. valueOf() 是在 Enum 中定义的 static 方法 ...

  4. python基础-2 编码转换 pycharm 配置 运算符 基本数据类型int str list tupple dict for循环 enumerate序列方法 range和xrange

    1.编码转换 unicode 可以编译成 UTF-U GBK 即 #!/usr/bin/env python # -*- coding:utf-8 -*- a = '测试字符' #默认是utf-8 a ...

  5. [Codeforces 1191D] Tokitsukaze, CSL and Stone Game(博弈论)

    [Codeforces 1191D] Tokitsukaze, CSL and Stone Game(博弈论) 题面 有n堆石子,两个人轮流取石子,一次只能从某堆里取一颗.如果某个人取的时候已经没有石 ...

  6. 洛谷P4391 [BOI2009]Radio Transmission 无线传输

    (https://www.luogu.org/problemnew/show/P4391) 题目描述 给你一个字符串,它是由某个字符串不断自我连接形成的. 但是这个字符串是不确定的,现在只想知道它的最 ...

  7. python学习第四十四天斐波那契数列和yield关键词使用

    斐波那契数列是数学中的常见的算法,第一个第二个不算,从第三个开始,每个数的都是前面两个数的和,使用yield关键词把生成的数列保存起来,调用的时候再调用,下面举例说明一下 def fab(max): ...

  8. ssh1

    #coding=utf-8 import paramiko ssh = paramiko.SSHClient() #允许链接不在linux上.ssh文件中不在known_hosts文件中的主机 ssh ...

  9. wepy_two

    2.代码高亮WebStorm/PhpStorm(其他工具参见:wepy官网代码高亮) (1)打开Settings,搜索Plugins,搜索Vue.js插件并安装. (2) 打开Settings,搜索F ...

  10. pppd - 点对点协议守护进程

    总览 SYNOPSIS pppd [ tty_name ] [ speed ] [ options ] 描述 点对点协议 (PPP) 提供一种在点对点串列线路上传输资料流 (datagrams)的方法 ...