Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ########### hw 4 #############
- print([num for num in xrange(1000) if sum(map(int, str(num))) == 10])
- ################ hw 5 ################
- def occ(n, specific):
- for num in xrange(n):
- times = len([x for x in str(num) if str(specific) == x])
- yield (num, times)
- for num, times in occ(100,2):
- print("%s -> %s" % (num,times))
- ################ hw 6 ################
- def is_prime(num):
- if num in [0,1]:
- return False
- if num == 2:
- return True
- return False if num & 1 == 0 else not any(num % n == 0 for n in xrange(3,int(num**0.5),2))
- for n in xrange(100):
- print("%s %s prime" % (n,"is" if is_prime(n) else "is not"))
- ################ hw 7 ################
- def fib(num):
- a,b = 0,1
- while a + b < num:
- a, b = b, a + b
- yield b
- print(list(fib(100)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement