码迷,mamicode.com
首页 > 编程语言 > 详细

Learn Python the Hard Way

时间:2015-08-29 21:39:33      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

ex1.py

1 print "Hello World!"
2 print "Hello Qiwei"
3 print "I like typing this."
4 print "This is fun."
5 print Yay! Printing.
6 print "I‘d much rather you ‘not‘."
7 print I "said" do not touch this.

 

 

ex2.py  Comments and Pound Characters

1 #A comment, this is so you can read your program later.
2 #Anything after the # is ignored by python.
3 
4 print "I could have code like this." #and the comment after is ignored
5 
6 #You can also use a comment to "disable" or comment out a piece of code;
7 #print "This won‘t run."
8 
9 print "This will run."

 

 

ex3.py Numbers and Math

 1 print "I will now count my chickens:"
 2 
 3 print "Hens", 25 + 30 /6
 4 print "Roosters", 100 - 25 * 3 %4
 5 
 6 print "Now I will count the eggs:"
 7 
 8 print 3 + 2 + 1 -5 + 4 % 2 - 1 / 4 + 6
 9 
10 print "Is it true that 3 + 2 < 5 - 7?"
11 
12 print 3 + 2 < 5 - 7
13 
14 print "What is 3 + 2?", 3 + 2
15 print "What is 5 - 7?", 5 - 7
16 
17 print "Oh, that‘s why it‘s False."
18 
19 print "How about some more."
20 
21 print "Is it greater?", 5 > -2
22 print "Is it greater or equal", 5 >= -2
23 print "Is it less or equal?", 5 <= -2

 

 

ex4.py Variables And Names

 1 cars = 100
 2 space_in_a_car = 4.0
 3 drivers = 30
 4 passengers = 90
 5 cars_not_driven = cars - drivers
 6 cars_driven = drivers
 7 carpool_capacity = cars_driven * space_in_a_car
 8 average_passengers_per_car = passengers / cars_driven
 9 
10 print "There are", cars, "cars available."
11 print "There are only", drivers, "drivers available"
12 print "There will be", cars_not_driven, "empty cars today."
13 print "We can transprot", carpool_capacity, "people today."
14 print "We have", passengers, "to carpool today."
15 print "We need to put about", average_passengers_per_car, "in each car."

 

 

 

  

 

Learn Python the Hard Way

标签:

原文地址:http://www.cnblogs.com/elewei/p/4769811.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!