Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. If we list all the natural numbers <= 20 that are multiples of 3 xor 5, we get:
  2.  
  3. 3, 5, 6, 9, 10, 12, 18, 20
  4.  
  5. Note, 15 is not included because multiples of both 3 and 5 are excluded from the above series.
  6.  
  7. In a language of your choice, write a program that takes a positive integer 'N' as an argument and prints all multiples of 3 xor 5 up to (and including) N.
  8.  
  9.  
  10.  
  11. import itertools
  12.  
  13. def printmultiple (n):
  14. if n.isdigit():
  15. flag_3 = None
  16. flag_5 = None
  17.  
  18. if (n%3 == 0):
  19. flag_3 = True
  20. if (n%5 == 0):
  21. flag_5 = True
  22. if ( flag_3 == True or flag_5 == True):
  23. yield n
  24.  
  25. newlist = []
  26. arr = range(0,21)
  27. for i in arr:
  28. newlist.append(printmultiple(i))
  29.  
  30. print newlist
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement