#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. POJ3160 Father Christmas flymouse[强连通分量 缩点 DP]

    Father Christmas flymouse Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 3241   Accep ...

  2. Flooded!

    Flooded! Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5955   Accepted: 1800   Specia ...

  3. Mysql优化系列(2)--通用化操作梳理

    前面有两篇文章详细介绍了mysql优化举措:Mysql优化系列(0)--总结性梳理Mysql优化系列(1)--Innodb引擎下mysql自身配置优化 下面分类罗列下Mysql性能优化的一些技巧,熟练 ...

  4. mvc自定义全局异常处理

    异常信息处理是任何网站必不可少的一个环节,怎么有效显示,记录,传递异常信息又成为重中之重的问题.本篇将基于上篇介绍的html2cancas截图功能,实现mvc自定义全局异常处理.先看一下最终实现效果: ...

  5. AppBox升级进行时 - Entity Framework的增删改查

    AppBox 是基于 FineUI 的通用权限管理框架,包括用户管理.职称管理.部门管理.角色管理.角色权限管理等模块. Entity Framework新增数据 以新增用户为例,作为对比,先来看下使 ...

  6. Windows Iot:让Raspberry Pi跑起来(1)

    首先请大家原谅我的"不务正业",放着RabbitHub不写,各种系列的文章不写搞什么Iot,哈哈,最近心血来潮想搞个速度极快的遥控车玩,望着在角落的Raspberry Pi恶狠狠的 ...

  7. Sqlserver 语法总结

    修改列类型 alter table PRO_Element_b alter column matname varchar(1024) 更改一个表中的数据到另外一个表中 update a set a.n ...

  8. poj1986 LCA

    Distance Queries Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 11759   Accepted: 4157 ...

  9. 【poj2065】 SETI

    http://poj.org/problem?id=2065 (题目链接) 题意 题意半天看不懂..给你一个素数P(P<=30000)和一串长为n的字符串str[].字母'*'代表0,字母a-z ...

  10. nginx + mysql + php相关源码包及安装

    nginx + mysql + php安装 引言 完整的搭建一个nginx+php-fpm+mysql的服务器,一直是我向做的,不过一致没有完成过,这次工作需要,终于安装成功了 我列出了我遇到的一些问 ...