def is_prime(num): newnum = num - 1 while newnum > 1: if num % newnum == 0: return False newnum -= 1 if newnum > 1: continue return True def get_primes(num): og, c = num, [] while num > 0: if is_prime(num): c.append(num) num -= 1 if og > 1: c.append(2) return sorted(c, reverse=False)
def get_primes(n):nums = list(range(2, n+1))primes = []while len(nums) > 0:prime = nums[0]del nums[0]primes.append(prime)for i in range(len(nums)-1, -1, -1):if nums[i] % prime == 0:del nums[i]return primes- def is_prime(num):
- newnum = num - 1
- while newnum > 1:
- if num % newnum == 0:
- return False
- newnum -= 1
- if newnum > 1:
- continue
- return True
- def get_primes(num):
- og, c = num, []
- while num > 0:
- if is_prime(num):
- c.append(num)
- num -= 1
- if og > 1:
- c.append(2)
- return sorted(c, reverse=False)
test.assert_equals(d([14, 44, 67, 3, 87, 32]),[3, 14, 32, 44, 67, 87]) test.assert_equals(d([70, 6, 4, 55, 34, 3, 2, 76, 7, 1, 344, 5, 54]),[1, 2, 3, 4, 5, 6, 7, 34, 54, 55, 70, 76, 344])
test.assert_equals(s([14, 44, 67, 3, 87, 32]),[3, 14, 32, 44, 67, 87])test.assert_equals(s([70, 6, 4, 55, 34, 3, 2, 76, 7, 1, 344, 5, 54]),[1, 2, 3, 4, 5, 6, 7, 34, 54, 55, 70, 76, 344])- test.assert_equals(d([14, 44, 67, 3, 87, 32]),[3, 14, 32, 44, 67, 87])
- test.assert_equals(d([70, 6, 4, 55, 34, 3, 2, 76, 7, 1, 344, 5, 54]),[1, 2, 3, 4, 5, 6, 7, 34, 54, 55, 70, 76, 344])
test.assert_equals(r([14, 44, 67, 3, 87, 32]),[3, 14, 32, 44, 67, 87]) test.assert_equals(r([70, 6, 4, 55, 34, 3, 2, 76, 7, 1, 344, 5, 54]),[1, 2, 3, 4, 5, 6, 7, 34, 54, 55, 70, 76, 344])
test.assert_equals(f([14, 44, 67, 3, 87, 32]),[3, 14, 32, 44, 67, 87])test.assert_equals(f([70, 6, 4, 55, 34, 3, 2, 76, 7, 1, 344, 5, 54]),[1, 2, 3, 4, 5, 6, 7, 34, 54, 55, 70, 76, 344])- test.assert_equals(r([14, 44, 67, 3, 87, 32]),[3, 14, 32, 44, 67, 87])
- test.assert_equals(r([70, 6, 4, 55, 34, 3, 2, 76, 7, 1, 344, 5, 54]),[1, 2, 3, 4, 5, 6, 7, 34, 54, 55, 70, 76, 344])
test.assert_equals(sort([14, 44, 67, 3, 87, 32]),[3, 14, 32, 44, 67, 87]) test.assert_equals(sort([70, 6, 4, 55, 34, 3, 2, 76, 7, 1, 344, 5, 54]),[1, 2, 3, 4, 5, 6, 7, 34, 54, 55, 70, 76, 344])
test.assert_equals(sort_arr([14, 44, 67, 3, 87, 32]),[3, 14, 32, 44, 67, 87])test.assert_equals(sort_arr([70, 6, 4, 55, 34, 3, 2, 76, 7, 1, 344, 5, 54]),[1, 2, 3, 4, 5, 6, 7, 34, 54, 55, 70, 76, 344])- test.assert_equals(sort([14, 44, 67, 3, 87, 32]),[3, 14, 32, 44, 67, 87])
- test.assert_equals(sort([70, 6, 4, 55, 34, 3, 2, 76, 7, 1, 344, 5, 54]),[1, 2, 3, 4, 5, 6, 7, 34, 54, 55, 70, 76, 344])
In this kata you must create a function that accepts strings as an input. The goal is to return the biggest and smallest numbers in order of greatest to least in an array. The input may contain non-numeric characters, so watch out. If a number is given as input the program should return an empty array.
Ex. "12382hgsjas//6" --> [8, 1]
Ex. 12324334 --> []
Ex. ["gr", "0", 578898, "12", "shthj680000001gh"] --> [680000001, 12]
Happy coding, and good luck!
def small_big_num(infos):
if isinstance(infos, int): return []
elif isinstance(infos, str):
infos = [int(i) for i in infos if i.isdigit()]
return [max(infos), min(infos)]
test.assert_equals(small_big_num("1234245356//"), [6, 1])
test.assert_equals(small_big_num(12343678), [])