Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. #Why does it matter where my: print num_ly(1900,2000)is located?  I thought once we wrote it that we could call on it anywhere in out #code?
  2.  
  3. #for example, this works:
  4.  
  5. def num_ly(year1, year2):
  6.     n = 0
  7.     while year1 < year2:
  8.         print year1
  9.         if isleap(year1):
  10.             n = n + 1
  11.             print n
  12.         year1 = year1 +1  
  13.        
  14. def isleap(year1):
  15.     return year1 % 4 == 0 and (year1 % 100 != 0 or year1 % 400 == 0)
  16.  
  17. print num_ly(1900,2000)
  18.  
  19. #but this doesn't:
  20.  
  21. def num_ly(year1, year2):
  22.     n = 0
  23.     while year1 < year2:
  24.         print year1
  25.         if isleap(year1):
  26.             n = n + 1
  27.             print n
  28.         year1 = year1 +1  
  29.        
  30. print num_ly(1900,2000)
  31.  
  32. def isleap(year1):
  33.     return year1 % 4 == 0 and (year1 % 100 != 0 or year1 % 400 == 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement