Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. ########### hw 4 #############
  2.  
  3. print([num for num in xrange(1000) if sum(map(int, str(num))) == 10])
  4.  
  5. ################ hw 5 ################
  6.  
  7. def occ(n, specific):
  8. for num in xrange(n):
  9. times = len([x for x in str(num) if str(specific) == x])
  10. yield (num, times)
  11.  
  12. for num, times in occ(100,2):
  13. print("%s -> %s" % (num,times))
  14.  
  15. ################ hw 6 ################
  16.  
  17. def is_prime(num):
  18. if num in [0,1]:
  19. return False
  20. if num == 2:
  21. return True
  22.  
  23. return False if num & 1 == 0 else not any(num % n == 0 for n in xrange(3,int(num**0.5),2))
  24.  
  25. for n in xrange(100):
  26. print("%s %s prime" % (n,"is" if is_prime(n) else "is not"))
  27.  
  28. ################ hw 7 ################
  29.  
  30.  
  31. def fib(num):
  32. a,b = 0,1
  33. while a + b < num:
  34. a, b = b, a + b
  35. yield b
  36.  
  37. print(list(fib(100)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement