diff --git a/ex1.py b/ex1.py new file mode 100644 index 0000000..c3708dd --- /dev/null +++ b/ex1.py @@ -0,0 +1,7 @@ +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.' diff --git a/ex2.py b/ex2.py new file mode 100644 index 0000000..7f325da --- /dev/null +++ b/ex2.py @@ -0,0 +1,9 @@ +# A comment, this is so you can read your program later. +# Anything after the # is ignored by 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 will run." diff --git a/ex3.py b/ex3.py new file mode 100644 index 0000000..42fcd7b --- /dev/null +++ b/ex3.py @@ -0,0 +1,33 @@ +# 在console输出 +print "I will now count my chickens:" + +# 在console输出,逗号后的部分做计算 +print "Hens", 25 + 30 / 6 +print "Roosters", 100 - 25 * 3 % 4 + +# 在console输出 +print "Now I will count the eggs:" + +# 计算 +print 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6 + +# 在console输出 +print "Is it true that 3 + 2 < 5 - 7?" + +# 在console输出不等式两边比较大小的结果 +print 3 + 2 < 5 - 7 + +# 在cosole输出,并做计算 +print "What is 3 + 2?", 3 + 2 +print "What is 5 - 7?", 5 - 7 + +# 在console输出 +print "Oh, that's why it's False." + +# 在console输出 +print "How about some more." + +# 在console输出,并比较不等式两边的大小 +print "Is it greater?", 5 > -2 +print "Is it greater or equal?", 5 >= -2 +print "Is it less or equal?", 5 <= -2 diff --git a/ex4.py b/ex4.py new file mode 100644 index 0000000..2346cdd --- /dev/null +++ b/ex4.py @@ -0,0 +1,16 @@ +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."