Advertisement
marquessbr

homework 2.7

Mar 7th, 2012
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. #2 GOLD STARS
  2.  
  3. #Define a procedure,
  4. #print_multiplication_table,
  5. #that takes as input a positive whole
  6. #number, and prints out a multiplication,
  7. #table showing all the whole number
  8. #multiplications up to and including the
  9. #input number. The order in which the
  10. #equations are printed must match exactly.
  11.  
  12. #print_multiplication_table(2)
  13. #1 * 1 = 1
  14. #1 * 2 = 2
  15. #2 * 1 = 2
  16. #2 * 2 = 4
  17.  
  18. def print_multiplication_table(n):
  19.     n1 = 1
  20.     while n1 < n + 1:
  21.         counter = 1
  22.         while (counter < n + 1):
  23.             n2 = 1
  24.             i = 1
  25.             while i == n2:
  26.                 m = n1 * counter
  27.                 s = '#' + str(n1) + ' * ' + str(counter) + ' = ' + str(m)
  28.                 print s
  29.                 n2 = n2 + 1
  30.             counter = counter + 1
  31.         n1 = n1 + 1
  32.     return
  33.  
  34. print_multiplication_table(3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement