11""" 
2+ Problem 7: https://projecteuler.net/problem=7 
3+ 
24By listing the first six prime numbers: 
35
46    2, 3, 5, 7, 11, and 13 
79""" 
810
911
10- def  isprime (number ):
12+ def  isprime (number : int ) ->  bool :
13+     """Determines whether the given number is prime or not""" 
1114    for  i  in  range (2 , int (number  **  0.5 ) +  1 ):
1215        if  number  %  i  ==  0 :
1316            return  False 
1417    return  True 
1518
1619
17- def  solution (n ) :
20+ def  solution (nth :  int   =   10001 )  ->   int :
1821    """Returns the n-th prime number. 
1922
2023    >>> solution(6) 
@@ -29,34 +32,38 @@ def solution(n):
2932    229 
3033    >>> solution(100) 
3134    541 
35+     >>> solution() 
36+     104743 
3237    >>> solution(3.4) 
3338    5 
3439    >>> solution(0) 
3540    Traceback (most recent call last): 
3641        ... 
37-     ValueError: Parameter n  must be greater or equal to one. 
42+     ValueError: Parameter nth  must be greater or equal to one. 
3843    >>> solution(-17) 
3944    Traceback (most recent call last): 
4045        ... 
41-     ValueError: Parameter n  must be greater or equal to one. 
46+     ValueError: Parameter nth  must be greater or equal to one. 
4247    >>> solution([]) 
4348    Traceback (most recent call last): 
4449        ... 
45-     TypeError: Parameter n  must be int or passive of cast to int. 
50+     TypeError: Parameter nth  must be int or passive of cast to int. 
4651    >>> solution("asd") 
4752    Traceback (most recent call last): 
4853        ... 
49-     TypeError: Parameter n  must be int or passive of cast to int. 
54+     TypeError: Parameter nth  must be int or passive of cast to int. 
5055    """ 
5156    try :
52-         n  =  int (n )
57+         nth  =  int (nth )
5358    except  (TypeError , ValueError ):
54-         raise  TypeError ("Parameter n must be int or passive of cast to int." )
55-     if  n  <=  0 :
56-         raise  ValueError ("Parameter n must be greater or equal to one." )
59+         raise  TypeError (
60+             "Parameter nth must be int or passive of cast to int." 
61+         ) from  None 
62+     if  nth  <=  0 :
63+         raise  ValueError ("Parameter nth must be greater or equal to one." )
5764    primes  =  []
5865    num  =  2 
59-     while  len (primes ) <  n :
66+     while  len (primes ) <  nth :
6067        if  isprime (num ):
6168            primes .append (num )
6269            num  +=  1 
0 commit comments