Skip to content

Commit 97a28e1

Browse files
committed
add ex1~6
1 parent 6475267 commit 97a28e1

6 files changed

Lines changed: 86 additions & 0 deletions

File tree

learn_py_the_hard_way/ex1.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env python
2+
print "Hello World!"
3+
print "Hello Again"
4+
print "I like typing this."
5+
print "This is fun."
6+
print 'Yay! Printing.'
7+
print "I'd much rather you 'not'"
8+
print 'I "said" do not touch this.'

learn_py_the_hard_way/ex2.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env python
2+
## A coment, this is so you can read your program letter
3+
# Anything after the # is ignored by python
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 some code
7+
# print "This won't run"
8+
print "This will run"

learn_py_the_hard_way/ex3.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
print "I will now count my chickens."
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+
print "How about some more"
19+
20+
print "Is it greater?", 5 > -2
21+
print "Is it greater or equal", 5 >= -2
22+
print "Is it less or equal?", 5 <= -2

learn_py_the_hard_way/ex4.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python
2+
3+
cars = 100
4+
space_in_a_car = 4.0
5+
drivers = 30
6+
passengers = 90
7+
cars_not_driven = cars - drivers
8+
cars_driven = drivers
9+
carpool_capacity = cars_driven * space_in_a_car
10+
average_passengers_per_car = passengers / cars_driven
11+
print "There are", cars, "cars available."
12+
print "There are only", drivers, "drivers available."
13+
print "There will be", cars_not_driven, "empty cars today."
14+
print "We can transport", carpool_capacity, "people today."
15+
print "We have", passengers, "to carpool today."
16+
print "We need to put about", average_passengers_per_car, "in each car."

learn_py_the_hard_way/ex5.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python
2+
my_name = 'Zed A. Shaw'
3+
my_age = 35 # not a lie
4+
my_height = 74 # inches
5+
my_weight = 180 # lbs
6+
my_eyes = 'Blue'
7+
my_teeth = 'White'
8+
my_hair = 'Brown'
9+
print "Let's talk about %s." % my_name
10+
print "He's %d inches tall." % my_height
11+
print "He's %d pounds heavy." % my_weight
12+
print "Actually that's not too heavy."
13+
print "He's got %s eyes and %s hair." % (my_eyes, my_hair)
14+
print "His teeth are usually %s depending on the coffee." % my_teeth
15+
# this line is tricky, try to get it exactly right
16+
print "If I add %d, %d, and %d I get %d." % (my_age, my_height, my_weight, my_age + my_height + my_weight)

learn_py_the_hard_way/ex6.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python
2+
3+
x = "There are %d types of people." % 10
4+
binary = "binary"
5+
do_not = "don't"
6+
y = "Those who know %s and those who %s." % (binary, do_not)
7+
print x
8+
print y
9+
print "I said: %r." % x
10+
print "I also said: '%s'." % y
11+
hilarious = False
12+
joke_evaluation = "Isn't that joke so funny?! %r"
13+
print joke_evaluation % hilarious
14+
w = "This is the left side of..."
15+
e = "a string with a right side."
16+
print w + e

0 commit comments

Comments
 (0)