brewersfan1976

ch2-ex4.py

Jul 3rd, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. column1 = "number"
  2. column2 = "squared"
  3. column3 = "cubed"
  4.  
  5. print column1.rjust(20), column2.rjust(20), column3.rjust(20)
  6.  
  7. column1 = "------"
  8. column2 = "-------"
  9. column3 = "-----"
  10.  
  11. print column1.rjust(20), column2.rjust(20), column3.rjust(20)
  12. print " "
  13.  
  14. x = 1
  15. y = 0
  16. z = 0
  17.  
  18. while (x <= 10):
  19.    y = x * x
  20.    z = x * x * x
  21.    
  22.    # we will now find the prime numbers and only print prime numbers
  23.    
  24.    count = 1
  25.    div = 2
  26.    while (div < x):
  27.       if (x % div == 0):
  28.          count = count + 1
  29.       div = div + 1
  30.      
  31.    if (count == 1):
  32.       print str(x).rjust(20), str(y).rjust(20), str(z).rjust(20)
  33.      
  34.    x = x + 1
Advertisement
Add Comment
Please, Sign In to add comment