From a12c4c98e47cc63b04c239c56fa34152d0d1cde8 Mon Sep 17 00:00:00 2001 From: Phil Cohen Date: Thu, 12 Apr 2012 21:54:58 -0700 Subject: [PATCH] example 5 extra credit --- ex5.py | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/ex5.py b/ex5.py index 4049975..5b3755c 100644 --- a/ex5.py +++ b/ex5.py @@ -1,18 +1,35 @@ -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' +name = 'Zed A. Shaw' +age = 35 # not a lie +height = 74 # inches +weight = 180 # lbs +eyes = 'Blue' +teeth = 'White' +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 "Let's talk about %s." % name +print "He's %d inches tall." % height +print "He's %d pounds heavy." % 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 +print "He's got %s eyes and %s hair." % (eyes, hair) +print "His teeth are usually %s depending on the coffee." % teeth # this line is tricky, 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) \ No newline at end of file + age, height, weight, age + height + weight) + +# extra credit + +# Change all the variables so there isn't the my_ in front. Make sure you +# change the name everywhere, not just where you used = to set them. + +# Try more format characters. %r is a very useful one. It's like saying +# "print this no matter what". +print "print %r no matter what" % (1 + 2 + 3) + +# Search online for all of the Python format characters. + +# Try to write some variables that convert the inches and pounds to +# centimeters and kilos. Do not just type in the measurements. Work out the +# math in Python. +print "%d inches is the same as %.02f centimeters" % (5.0, (5.0 * 2.54)) +print "%d pounds is the same as %.04f kilos" % (180.0, (180.0 * 0.4536))