Advertisement
nosthemerc

"Python %s", % "formating"

Nov 12th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. name = 'Jacob H. Freedman'
  2. age = 26
  3. height = 66 # inches
  4. weight = 135 # lbs
  5. height_in_cm = height * 2.54
  6. weight_in_kg = weight * 0.45359237
  7. eyes = 'Blue'
  8. teeth = 'White'
  9. hair = 'Brown'
  10.  
  11. print "Let's talk about %s." % name
  12. print "He's %d inches tall." % height
  13. print "He's %d pounds heavy." % weight
  14. print "Actually that's not too heavy."
  15. print "He's got %s eyes and %s hair." % (eyes, hair)
  16. print "His teeth are usually %s depending on his coffee." % teeth
  17.  
  18. #tricky line
  19. print "If I add %d, %d, and %d I get %d." % (
  20.     age, height, weight, age + height + weight)
  21. print "Wait!  We're in Europe!"
  22. print "He's %.2f cm tall." % height_in_cm
  23. print "He's %.2f kg heavy." % weight_in_kg
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement