Esempio n. 1
0
def test_prime_invalid_values():
    with pytest.raises(TypeError) as err:
        is_prime("1")

    with pytest.raises(TypeError) as err:
        is_prime(10.1)

    with pytest.raises(TypeError) as err:
        is_prime([1, 2, 3])

    with pytest.raises(TypeError) as err:
        is_prime((1, 2, 3))

    with pytest.raises(TypeError) as err:
        is_prime(None)
Esempio n. 2
0
def prime_before(number):
    '''The Function will return the prime number that comes first
    when we count from backwards of the given number
    Note: The number passed should be greater than 2'''
    if not is_int(number):
        raise TypeError("Unsupported format")
    if number <= 2:
        raise ValueError('Invalid input')
    for i in range(number - 1, 1, -1):
        if is_prime(i):
            return i
    #This return will never be executed
    return None
def product_prime(number):
    '''This function returns the product of the numbers which are prime factors
    of a given number'''
    if not is_int(number):
        raise TypeError(f'unsupported format, {type(number)} is in the place of"integer"')
    if number <= 0:
        raise ValueError("pass an integer greater than 0")
    product = 1
    for i in range(2, number+1):
        if number % i == 0 and is_prime(i):
            product = product * i
    return product
    
Esempio n. 4
0
def test_prime_valid_values():
    assert is_prime(10) == False
    assert is_prime(100) == False
    assert is_prime(11) == True
    assert is_prime(101) == True
    assert is_prime(140) == False