Learn python the hard way. python test program 2016.04.27

简介: 1 # this will not be printed in python ! 2 print "I could have code like this." # and the comment after is ignored 3 4 # You can also us...
  1 # this will not be printed in python !
  2 print "I could have code like this." # and the comment after is ignored
  3 
  4 # You can also use a comment to "disable" or comment out a piece of code:
  5 # print "This won't run. "
  6 
  7 print "This won't run. "
  8 
  9 print "I will now count my chickens:"
 10 
 11 print "Hens", 25 + 30 / 6
 12 print "Roosters", 100 - 25 * 3 % 4
 13 
 14 print "Now I will count the eggs:" 
 15 
 16 print 3+2+1-5+4%2-1/4+6
 17 print "Is it true that 3 + 2 < 5 - 7 ?"
 18 
 19 print "What is 3+2 ?", 3+2
 20 print "What is 5-7 ?", 5-7
 21 
 22 print "Oh, that's why it's False."
 23 
 24 print "How about Some more."
 25 
 26 print "Is it greater ?", 5 > -2 
 27 print "Is it greater or equal ?", 5 >= -2 
 28 print "Is it less or equal ?", 5 <= -2
 29 
 30 
 31 
 32 # Exercise 5: More Variable and Printing.
 33 my_name = 'Zed A. Shaw'
 34 my_age = 35 # not a lie
 35 my_height = 74 # inches
 36 my_weight = 180 # lbs
 37 my_eyes = 'Blue'
 38 my_teeth = 'White'
 39 my_hair = 'Brown'
 40 
 41 print "Let's talk about %s." % my_name
 42 print "He's %d inches tall." % my_height
 43 print "He's %d pounds heavy." % my_weight
 44 print "Actually that's not too heavy."
 45 print "He's got %s eyes and %s hair." % (my_eyes, my_hair)
 46 print "His teeth are usually %s depending on the coffee." % my_teeth
 47 
 48 # this line is ticky, try to get it exactly right
 49 print "If I add %d, %d,  and %d I get %d." % (
 50     my_age, my_height, my_weight, my_age + my_height + my_weight)
 51 
 52 
 53 
 54 # Exercise 4: Variables and Names 
 55 cars = 100
 56 space_in_a_car = 4.0
 57 drivers = 30
 58 passengers = 90
 59 cars_not_driven = cars -drivers
 60 cars_driven = drivers
 61 carpool_capacity = cars_driven * space_in_a_car
 62 average_passengers_per_car = passengers / cars_driven
 63 
 64 print "There are", cars, "cars available."
 65 print "There are only", drivers, "drivers available"
 66 print "There will be", cars_not_driven, "empty cars today."
 67 print "We can transport", carpool_capacity, "people today."
 68 print "We have", passengers, "to carpool today."
 69 print "We need to put about", average_passengers_per_car, "in each car."
 70 
 71 
 72 
 73 x = "They are %d types of people." % 10
 74 binary = "binary"
 75 do_not = "don't"
 76 y = "Those who know %s and those who %s." % (binary, do_not)
 77 
 78 print x
 79 print y
 80 
 81 print "I said: %r." % x
 82 print "I also said: '%s'." % y
 83 
 84 hilarious = True
 85 joke_evaluation = "Isn't that joke so funny ?! %r" 
 86 
 87 print joke_evaluation % hilarious
 88 
 89 w = "This is the left side of ..."
 90 e = "a string with a right side."
 91 
 92 print w+e
 93 
 94 
 95 
 96 print "Mary had a little lamb."
 97 print "Its fleece was white as %s." % 'snow'
 98 print "And everywhere that Mary went."
 99 print "." * 10 # what'd that do ?
100 
101 end1 = "C"
102 end2 = "h"
103 end3 = "e"
104 end4 = "e"
105 end5 = "s"
106 end6 = "e"
107 end7 = "B"
108 end8 = "u"
109 end9 = "r"
110 end10 = "g"
111 end11 = "e"
112 end12 = "r"
113 
114 # watch that comma at the end. try removing it to see what happens 
115 print end1 + end2 + end3 + end4 + end5 + end6 ,  # use the , it output: Cheese Burger 
116 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()

 

 

相关文章
|
iOS开发 MacOS Python
【Python】已解决:(Pycharm切换Python版本后报错)No Python at “C:\Program Files\Python39\python.exe”
【Python】已解决:(Pycharm切换Python版本后报错)No Python at “C:\Program Files\Python39\python.exe”
1916 0
【Python】已解决:(Pycharm切换Python版本后报错)No Python at “C:\Program Files\Python39\python.exe”
|
算法 Java C语言
【经典算法】LeetCode25:K 个一组翻转链表(Java/C/Python3,Hard)
【经典算法】LeetCode25:K 个一组翻转链表(Java/C/Python3,Hard)
668 1
|
TensorFlow 算法框架/工具 Python
成功解决tensorflow\contrib\learn\python\learn\datasets\base._internal_retry.<locals>.wrap.<locals>.wrapp
成功解决tensorflow\contrib\learn\python\learn\datasets\base._internal_retry.<locals>.wrap.<locals>.wrapp
|
TensorFlow 算法框架/工具 Python
成功解决tensorflow\contrib\learn\python\learn\datasets\mnist.py: maybe_download (from tensorflow.contri
成功解决tensorflow\contrib\learn\python\learn\datasets\mnist.py: maybe_download (from tensorflow.contri
|
Web App开发 人工智能 测试技术
书籍:Learn Web Development with Python - 2018.pdf
简介 使用最流行的Python Web框架(Django)进行Web编程的Python编程综合指南 主要特点 了解使用Python编程和构建Web应用程序的基础知识 使用Django从头开始构建Web应用程序 使用最新的Django框架创建真实的RESTful Web服务 图书说明 如果您想使用Django开发完整的Python Web应用程序,这个学习路径适合您。
|
传感器 人工智能 机器人
python人工智能机器人工具书籍: Learn Robotics Programming(python and Raspberry Pi 3) - 2018
简介 人工智能和智能机器人将精确有效地执行不同的任务。 Raspberry Pi和Python的组合在制作这些机器人时非常有效。 本书首先向您介绍机器人的基本结构,以及如何规划,构建和编程。 当您完成本书时,您将逐渐进步添加不同的输出和传感器,学习新的建筑技能,以及使用传感器编写有趣行为的代码。
|
机器学习/深度学习 数据采集 算法
|
数据采集 机器学习/深度学习 算法
|
机器学习/深度学习 算法 数据挖掘
Scikit Learn: 在python中机器学习
Warning 警告:有些没能理解的句子,我以自己的理解意译。 翻译自:Scikit Learn:Machine Learning in Python 作者: Fabian Pedregosa, Gael Varoquaux 先决条件 Nump...
1508 0

推荐镜像

更多