笨办法学Python (exercise1-15)
#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)的更多相关文章
- 笨办法学 Python (Learn Python The Hard Way)
最近在看:笨办法学 Python (Learn Python The Hard Way) Contents: 译者前言 前言:笨办法更简单 习题 0: 准备工作 习题 1: 第一个程序 习题 2: 注 ...
- 笨办法学 Python (第三版)(转载)
笨办法学 Python (第三版) 原文地址:http://blog.sina.com.cn/s/blog_72b8298001019xg8.html 摘自https://learn-python ...
- 笨办法学python - 专业程序员的养成完整版PDF免费下载_百度云盘
笨办法学python - 专业程序员的养成完整版PDF免费下载_百度云盘 提取码:xaln 怎样阅读本书 由于本书结构独特,你必须在学习时遵守几条规则 录入所有代码,禁止复制粘贴 一字不差地录入代码 ...
- 笨办法学Python 3|百度网盘免费下载|新手基础入门书籍
点击下方即可百度网盘免费提取 百度网盘免费下载:笨办法学Python 3 提取码:to27 内容简介: 本书是一本Python入门书,适合对计算机了解不多,没有学过编程,但对编程感兴趣的读者学习使用. ...
- 《笨办法学 Python(第四版)》高清PDF|百度网盘免费下载|Python编程
<笨办法学 Python(第四版)>高清PDF|百度网盘免费下载|Python编程 提取码:jcl8 笨办法学 Python是Zed Shaw 编写的一本Python入门书籍.适合对计算机 ...
- 笨办法学python 第四版 中文pdf高清版|网盘下载内附提取码
笨办法学 Python是Zed Shaw 编写的一本Python入门书籍.适合对计算机了解不多,没有学过编程,但对编程感兴趣的朋友学习使用.这本书以习题的方式引导读者一步一步学习编 程,从简单的打印一 ...
- 笨办法学Python - 习题1: A Good First Program
在windows上安装完Python环境后,开始按照<笨办法学Python>书上介绍的章节进行练习. 习题 1: 第一个程序 第一天主要是介绍了Python中输出函数print的使用方法, ...
- 笨办法学python 13题:pycharm 运行
笨办法学python 13题 代码: # -*- coding: utf-8 -*- from sys import argv # argv--argument variable 参数变量 scrip ...
- 《笨办法学Python 3》python入门书籍推荐|附下载方式
<笨办法学Python 3>python入门书籍免费下载 内容简介 本书是一本Python入门书,适合对计算机了解不多,没有学过编程,但对编程感兴趣的读者学习使用.这本书以习题的方式引导读 ...
随机推荐
- ArrayList,Vector,LinkedList
在java.util包中定义的类集框架其核心的组成接口有如下:·Collection接口:负责保存单值的最大父接口 |-List子接口:允许保存重复元素,数据的保存顺序就是数据的增加顺序: |-Set ...
- Matlab的68个小常识
1.det(A)可以计算矩阵A的行列式值.inv(A)可以计算矩阵A的逆 2.rref(A)可以将矩阵A化为行简化阶梯梯形矩阵 3.eps是系统定义的容许误差,eps=2.2204*10-16 4.p ...
- C#.NET 大型企业信息化系统集成快速开发平台 4.2 版本 - 所有的基础数据都可以恢复删除
客户的需求如下: 所有基礎信息需要記錄創建人,創建時間,更改人,更改時間,刪除人,刪除時間.有停用基礎信息功能(停用不是刪除,只是暫時停用).基礎信息可以查出已經刪除的信息(有選項可以選擇),有方法把 ...
- 基本排序(二)插入排序(直接插入、Shell、折半)
插入排序是常见的内部排序之一.常见的插入排序包括直接插入排序.Shell排序.折半排序.本篇主要介绍这三个排序. 转载请注明出处——http://www.cnblogs.com/zrtqsk/p/38 ...
- tensorflow学习笔记五:mnist实例--卷积神经网络(CNN)
mnist的卷积神经网络例子和上一篇博文中的神经网络例子大部分是相同的.但是CNN层数要多一些,网络模型需要自己来构建. 程序比较复杂,我就分成几个部分来叙述. 首先,下载并加载数据: import ...
- [LeetCode] Implement Trie (Prefix Tree)
Implement a trie with insert, search, and startsWith methods. Note:You may assume that all inputs ar ...
- AppBox升级进行时 - Any与All的用法(Entity Framework)
AppBox 是基于 FineUI 的通用权限管理框架,包括用户管理.职称管理.部门管理.角色管理.角色权限管理等模块. 属于某个角色的用户列表(Any的用法) 使用Subsonic,我们有两种方法获 ...
- C#进阶系列——动态Lamada(二:优化)
前言:前几天写了一篇动态Lamada的文章C#进阶系列——动态Lamada,受园友xiao99的启发,今天打算来重新优化下这个动态Lamada的工具类.在此做个笔记,以免以后忘了. 一.原理分析 上篇 ...
- C#-WebForm-WebForm开发基础
1.C/S 客户端应用程序 WinForm WPF 平级 数据是存放在其他的电脑上或服务器上 需要从服务器上下载相应的数据,在本地电脑上的客户端里进行加工 数据的加工是在用户的电脑上执行的,会对用户的 ...
- css 拾遗
1, 实现尖角 <style> .up{ border-top: 30px solid red; border-right:30px solid gold; border-bottom:3 ...