#exercise1
print "Hello world!"
print "Hello Again"
print "I like typing this."
print "this is fun."
print 'Yay! Printing.'
print "I'd much rather you 'not'."
print 'I "said" do not touch this.'

#exercise2 #号的用处
#exercise3 数字和数学计算
print "Hen",25+30/6
print "Hen",round(25+30/6,1) #round函数返回浮点型数据
print 1/4
print "Roosters", 25*3%4 #先乘法后求模
print 3+2<5-7
print "is it greater?",5>-2
#exercise4 变量
cars=100
space_in_a_car=4.0
drivers=30
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 "we need to put about",average_passengers_per_car,"in each car."
#exercise5 标准文本格式,变量嵌套在文本里面
my_name='caijiangyao'
my_age=24
my_height=43
my_weigh=45
my_eye='black'
my_teeth='white'
my_hair='brown'

print "let's talk about %s." % my_name #变量为字符串时要用%s
print "she is %d. inches tall." %my_height #变量为数值时要用%d
print "she's got %s eyes and %s hair" % (my_eye,my_teeth) #多个变量嵌套时
print "if i add %d,%d and %d i get %d." %(my_age,my_height,my_weigh,my_age+my_height+my_weigh)
print "我的身高%d" % my_height

#exercise6 字符串和文本
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 #r引用简写的变量名x
print "i also said: '%s'" %y #引用简写的变量名y
print "i also said: %r" %y

hilarious=False
joke_evalution="isn't that joke so funny?! %r"
print joke_evalution %hilarious

w="this is the left side of ..."
e="a string with a right side."
print w+e

#exercise7 更多的打印
print "mary had a little lamp."
print "its fleece was white as %s" %'snow'
print "and everywhere that mary went."
print "."*10 #文本字符串与数字乘 10个..........

end1="c"
end2="h"
end3="e"
end4="e"
end5="s"
end6="e"
end7="b"
end8="u"
end9="r"
end10="g"
end11="e"
end12="r"
print end1+end2+end3+end4+end5+end6,
print end7+end8+end9+end10+end11+end12 #,使得两条print的记录连在一起

#exercise8 打印

打印 "%r"与"%s"有什么不同,"%r"用来做debug比较好,因为它会显示变量的原始数据(raw data),而其他的符号则是用来向用户显示输出的。
formatter="%r %r %r %r"
print formatter %(1,2,3,4)
print formatter %("one","two","three","four")
print formatter %(
"i had this ting",
"that you could type up right.",
"but it didn't sing.",
"so i said goodnight.")

#exercise9 打印,打印 ,打印
days="Mon Tue Wed Thu fri sat sun"
months="jan\nfeb\nmar\napr\nmay\njun"
print "here is the days:",days
print "here are the months:",months

print """ there's someting going on here.
with three double-quotes.
even 4 lines if we want , or 5 ,or 6.
"""
#exercise10 那是什么
print "i am 6'2\" tall."
print 'i am 6\'2" tall.' #在容易混杂的符号前加上反斜杠\(back slash)

tabby_cat="\ti'm tabbled in."
print tabby_cat
persian_cat="i'm split\non a line."#\n换行
print persian_cat
blackslach_cat="i'm\\ a\\cat."
print blackslach_cat #另一个\是原文中有的
fat_cat="""
i'll do a list:
\t*catfood
\t*catnip\n\t* grass
"""
print fat_cat
#exercise11 提问
print "how old are you?",
age=raw_input()
print "how tall are you?",
height =raw_input()
print "how much do you weight?",
weight =raw_input()

print "so you are %r old,%r tall,and %r heavy." %(age,height,weight)

#exercise12 提示别人
y=raw_input("name?")#这句话会用 “Name?” 提示用户,然后将用户输入的结果赋值给变量 y。
#这就是我们提问用户并且得到答案的方式。
age=raw_input("how old are you?")
height=raw_input("how tall are you?")
weight=raw_input("how much do you weigh?")
print "so you are %r old,%r tall,and %r heavy." %(age,height,weight)

#exercise13 参数,解压,变量
from sys import argv
script, first, second, third = argv
print "the script is called:",script
print "your first variable is:",first
print "your second variable is:",second
print "your third variable is:",third
python ex13.py first 2nd 3rd

#exercise14 参数,解压,变量
from sys import argv
ex1.py, zed=argv
prompt ='>'
print "

#exercise15 读文件
from sys import argv
script,filename=argv
txt=open(filename)
print "here's your file %r:" %filename
print txt.read()

print "type the filename again:"
ex15_sample
file_again=raw_input("> ")
txt_again=open(file_again)
print txt_again.read()

笨办法学Python (exercise1-15)的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. COGS130. [USACO Mar08] 游荡的奶牛[DP]

    130. [USACO Mar08] 游荡的奶牛 ★☆   输入文件:ctravel.in   输出文件:ctravel.out   简单对比时间限制:1 s   内存限制:128 MB 奶牛们在被划 ...

  2. Django博客功能实现—文章评论的显示

    功能:在打开文章之后,能在文章下面是显示文章的评论,有父级评论.思路:在文章详情的视图里面,获取这个文章的全部评论,得到显示列表,然后用模板显示出来.步骤:一,在views.py的文章详情中获取评论: ...

  3. codevs 2894 保留小数

    时间限制: 1 s 空间限制: 128000 KB 题目等级 : 白银 Silver 题目描述 Description 给你一个实数,小数点后不超过50位,请你保留到小数点后n位(四舍五入!!!) 输 ...

  4. C#.NET 大型企业信息化系统集成快速开发平台 4.1 版本 - 面向数据库SQL语句的应用开发二

    很多传统企业.包括系统集成类的IT企业,若不是从事专业软件开发领域的,能做出一套适合本公司企业信息化的灵活的信息系统还是很有难度的,还有一些已经多年不写程序的资深开发人员,初学者,都难把一个整套系统实 ...

  5. Netron开发快速上手(一):GraphControl,Shape,Connector和Connection

    版权所有,引用请注明出处:<<http://www.cnblogs.com/dragon/p/5203663.html >> 本文所用示例下载FlowChart.zip 一个用 ...

  6. [[iso教程]] 《4个月ios实体教程》全网最新、最全ios视频教程

    全网最新.最全ios视频教程 内容简介 <ios实体教程>主要介绍如何使用iOS提供的强大工具集创建iOS应用.全视频对iOS操作系统做了全面的介绍,首先讲解如何构建应用程序的用户界面,涵 ...

  7. windows xp 连接USB网络打印机服务器(通用所有usb网络打印机服务器的安装)

    usb网络打印机服务器是HP1101U 打印机是 hp1108 需要准备的其他东西:1.HP1108的驱动 首先,接好线,保证usb hp1101u能正常访问,这款USB一旦接入了网络,会分配一个ip ...

  8. js 判断各种数据类型

    了解js的都知道, 有个typeof  用来判断各种数据类型,有两种写法:typeof   xxx   ,typeof(xxx) 如下实例: typeof   2      输出   number   ...

  9. CURL

    基本语法: function curl($url){ $ch=curl_init();  //初始化 curl_setopt($ch, CURLOPT_URL, $url); //核心 curl_se ...

  10. iOS小知识点(UI部分)

    1. 父视图通过Tag来找到UIView UIView *targetView = [superView viewWithTag:10];//只在当前视图以及subviews中找,不能再孙子中找. 2 ...