Learn python the hard way. python test program 2016.04.27
# this will not be printed in 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 won't run. " print "I will now count my chickens:" print "Hens", 25 + 30 / 6
print "Roosters", 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 "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 # Exercise 5: More Variable and Printing.
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 "He's got %s eyes and %s hair." % (my_eyes, my_hair)
print "His teeth are usually %s depending on the coffee." % my_teeth # this line is ticky, 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) # Exercise 4: Variables and Names
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 "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." x = "They 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 = True
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 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 , # use the , it output: Cheese Burger
print end7 + end8 + end9 + end10 + end11 + end12 # remove the , it output: Cheese \\ Burger;
class Song(object):
def __init__(self, lyrics):
self.lyrics = lyrics
def sing_me_s_song(self):
for line in self.lyrics:
print line
happy_bday = Song(["Happy birthday to you",
"I don't want to get sued",
"So, I will stop right there"])
bulls_on_parade = Song(["There rally around the family",
"With pockets full of shells"])
happy_bday.sing_me_s_song()
bulls_on_parade.sing_me_s_song()
Learn python the hard way. python test program 2016.04.27的更多相关文章
- Python之路,Day1 - Python基础1
本节内容 Python介绍 发展史 Python 2 or 3? 安装 Hello World程序 变量 用户输入 模块初识 .pyc是个什么鬼? 数据类型初识 数据运算 表达式if ...else语 ...
- install Python 2.7 and Python 3.3 on CentOS 6
来自:http://toomuchdata.com/2014/02/16/how-to-install-python-on-centos/ In this guide I will show you ...
- Python之路,Day1 - Python基础1(转载Alex)
本节内容 Python介绍 发展史 Python 2 or 3? 安装 Hello World程序 变量 用户输入 模块初识 .pyc是个什么鬼? 数据类型初识 数据运算 表达式if ...else语 ...
- Python之路,Day1 - Python基础1 --转自金角大王
本节内容 Python介绍 发展史 Python 2 or 3? 安装 Hello World程序 变量 用户输入 模块初识 .pyc是个什么鬼? 数据类型初识 数据运算 表达式if ...else语 ...
- 我的Python学习之路 Python的输入输出与基本数据类型
*** python中的变量不需要事先声明再使用,而可以直接来一个变量名,后面一个赋值,接着一个数据值,如 hw = "hello python",相当于Python能智能的根据你 ...
- 计算机基础+python安装注意问题+python变量介绍
1.什么是编程语言语言是一个事物与另外一个事物沟通的介质编程语言是程序员与计算机沟通的介质 2.什么是编程编程就是程序按照某种编程语言的语法规范将自己想要让计算机做的事情表达出来表达的结果就是程序,程 ...
- python基础系列教程——Python库的安装与卸载
python基础系列教程——Python库的安装与卸载 2.1 Python库的安装 window下python2.python3安装包的方法 2.1.1在线安装 安装好python.设置好环境变量后 ...
- python基础系列教程——Python的安装与测试:python的IDE工具PyDev和pycharm,anaconda
---恢复内容开始--- python基础系列教程——Python的安装与测试:python的IDE工具PyDev和pycharm,anaconda 从头开启python的开发环境搭建.安装比较简单, ...
- Python面试题之Python正则表达式re模块
一.Python正则表达式re模块简介 正则表达式,是一门相对通用的语言.简单说就是:用一系列的规则语法,去匹配,查找,替换等操作字符串,以达到对应的目的:此套规则,就是所谓的正则表达式.各个语言都有 ...
随机推荐
- SharePoint 2010 BCS - 简单实例(一)数据源添加
博客地址 http://blog.csdn.net/foxdave 本篇基于SharePoint 2010 Foundation. 我的数据库中有一个病人信息表Patient,现在我就想把这个表中的数 ...
- SpringMvc中的反射
controller中的方法,是通过反射调用的 spring监控controller中的注解,当命令符合某个注解的时候,通过反射,找到这个注解对应的方法,然后调用,处理完成得到返回值,再根据这个返回值 ...
- centos虚拟机,环境配置
yum安装 yum -y install 包名(支持*) :自动选择y,全自动yum install 包名(支持*) :手动选择y or n 1.安装vim Centos默认自带VI,功能没VIM丰富 ...
- php中常用的运算符
运算符 运算符是告诉PHP做相关运算的标识符号. PHP运算符一般分为算术运算符.赋值运算符.比较运算符.三元运算符.逻辑运算符.字符串连接运算符.错误控制运算符. 1.变量名记得加“$” 符: 2. ...
- 2014年3月份第2周51Aspx源码发布详情
MVC+EF某钢电子交易平台源码 2014-3-10 [VS2012]功能介绍:本源码是一套完整的电子交易平台系统,完全基于ASP.NET MVC+EF三层构架,开发环境为Visual Studio ...
- java获取获得Timestamp类型的当前系统时间。
java获取获得Timestamp类型的当前系统时间. java获取取得Timestamp类型的当前系统时间 格式:2010-11-04 16:19:42 方法1: Timestamp d = n ...
- Android异步更新UI的四种方式
Android异步更新UI的四种方式 2015-09-06 09:23 segmentfault 字号:T | T 大家都知道由于性能要求,android要求只能在UI线程中更新UI,要想在其他线程中 ...
- ACDream-C - Transformers' Mission(Dijastra最短路径)
dijstra求最短路径:经典应用题目: 题意:给你一个带权值无向图,权值是A点到B点的时间,然后告诉你起点,一个人可以去炸掉一个结点或多个节点,也可以派多个人,最终这些人在终点集合,问最后一个到达终 ...
- Helo command rejected: need fully-qualified hostname
Helo command rejected: need fully-qualified hostname问题 是由于postfix的配置文件(main.cf)有问题.其中有一个smtpd_sasl_l ...
- HDU 5823 (状压dp)
Problem color II 题目大意 定义一个无向图的价值为给每个节点染色使得每条边连接的两个节点颜色不同的最少颜色数. 对于给定的一张由n个点组成的无向图,求该图的2^n-1张非空子图的价值. ...